= Condensed managers and handler
This commit is contained in:
+19
-1
@@ -41,7 +41,7 @@ import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
|||||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.core.managers.AudioManager;
|
import net.dv8tion.jda.core.managers.AudioManager;
|
||||||
import offline.Ref;
|
import offline.Ref;
|
||||||
import trash.GuildMusicManager;
|
import trash.TrackScheduler;
|
||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
|
|
||||||
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||||
@@ -50,6 +50,24 @@ import utils.GlobalLog;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Main extends ListenerAdapter
|
public class Main extends ListenerAdapter
|
||||||
{
|
{
|
||||||
|
public class GuildMusicManager
|
||||||
|
{
|
||||||
|
public final AudioPlayer player;
|
||||||
|
public final TrackScheduler scheduler;
|
||||||
|
|
||||||
|
public GuildMusicManager(AudioPlayerManager manager)
|
||||||
|
{
|
||||||
|
player = manager.createPlayer();
|
||||||
|
scheduler = new TrackScheduler(player);
|
||||||
|
player.addListener(scheduler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioPlayerSendHandler getSendHandler()
|
||||||
|
{
|
||||||
|
return new AudioPlayerSendHandler(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class AudioPlayerSendHandler implements AudioSendHandler
|
public class AudioPlayerSendHandler implements AudioSendHandler
|
||||||
{
|
{
|
||||||
private final AudioPlayer audioPlayer;
|
private final AudioPlayer audioPlayer;
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package trash;
|
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a wrapper around AudioPlayer which makes it behave as an AudioSendHandler for JDA. As JDA calls canProvide
|
|
||||||
* before every call to provide20MsAudio(), we pull the frame in canProvide() and use the frame we already pulled in
|
|
||||||
* provide20MsAudio().
|
|
||||||
*/
|
|
||||||
public class AudioPlayerSendHandler implements AudioSendHandler
|
|
||||||
{
|
|
||||||
private final AudioPlayer audioPlayer;
|
|
||||||
private AudioFrame lastFrame;
|
|
||||||
|
|
||||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer)
|
|
||||||
{
|
|
||||||
this.audioPlayer = audioPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canProvide()
|
|
||||||
{
|
|
||||||
lastFrame = audioPlayer.provide();
|
|
||||||
return lastFrame != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] provide20MsAudio()
|
|
||||||
{
|
|
||||||
return lastFrame.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOpus()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package trash;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holder for both the player and a track scheduler for one guild.
|
|
||||||
*/
|
|
||||||
public class GuildMusicManager {
|
|
||||||
/**
|
|
||||||
* Audio player for the guild.
|
|
||||||
*/
|
|
||||||
public final AudioPlayer player;
|
|
||||||
/**
|
|
||||||
* Track scheduler for the player.
|
|
||||||
*/
|
|
||||||
public final TrackScheduler scheduler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a player and a track scheduler.
|
|
||||||
* @param manager Audio player manager to use for creating the player.
|
|
||||||
*/
|
|
||||||
public GuildMusicManager(AudioPlayerManager manager) {
|
|
||||||
player = manager.createPlayer();
|
|
||||||
scheduler = new TrackScheduler(player);
|
|
||||||
player.addListener(scheduler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Wrapper around AudioPlayer to use it as an AudioSendHandler.
|
|
||||||
*/
|
|
||||||
public AudioPlayerSendHandler getSendHandler() {
|
|
||||||
return new AudioPlayerSendHandler(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user