Fix issues with queue not playing.

multithread-playback
Nekojimi 3 years ago
parent 9a6520f426
commit 4ec47df625
  1. 1
      src/main/java/moe/nekojimi/chords/Main.java
  2. 17
      src/main/java/moe/nekojimi/chords/MusicHandler.java
  3. 3
      src/main/java/moe/nekojimi/chords/QueueManager.java

@ -295,6 +295,7 @@ public class Main extends ListenerAdapter
// Get an audio manager for this guild, this will be created upon first use for each guild // Get an audio manager for this guild, this will be created upon first use for each guild
AudioManager audioManager = guild.getAudioManager(); AudioManager audioManager = guild.getAudioManager();
musicHandler = new MusicHandler(); musicHandler = new MusicHandler();
queueManager.setHandler(musicHandler);
// Create our Send/Receive handler for the audio connection // Create our Send/Receive handler for the audio connection
// EchoHandler handler = new EchoHandler(); // EchoHandler handler = new EchoHandler();

@ -25,7 +25,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
// private final LinkedList<Song> songQueue = new LinkedList<>(); // private final LinkedList<Song> songQueue = new LinkedList<>();
// private final Queue<byte[]> queue = new ConcurrentLinkedQueue<>(); // private final Queue<byte[]> queue = new ConcurrentLinkedQueue<>();
private final CircularByteBuffer audioBuffer = new CircularByteBuffer(3840 * 1024); private final CircularByteBuffer audioBuffer = new CircularByteBuffer(3840 * 1024);
private boolean playing = true; private boolean shouldPlay = true;
private int byteCount; private int byteCount;
private boolean arrayErr = false; private boolean arrayErr = false;
@ -121,14 +121,19 @@ public class MusicHandler implements AudioSendHandler, Closeable
public boolean isPlaying() public boolean isPlaying()
{ {
return playing; return player != null;
} }
public void setPlaying(boolean playing) public boolean isShouldPlay()
{ {
if (!this.playing && playing) return shouldPlay;
}
public void setShouldPlay(boolean shouldPlay)
{
if (!this.shouldPlay && shouldPlay)
nextSong(); nextSong();
this.playing = playing; this.shouldPlay = shouldPlay;
} }
@Override @Override
@ -136,7 +141,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
{ {
return player != null && player.has(1); return player != null && player.has(1);
// If we have something in our buffer we can provide it to the send system // If we have something in our buffer we can provide it to the send system
// return audioBuffer.getCurrentNumberOfBytes() > byteCount && playing; // return audioBuffer.getCurrentNumberOfBytes() > byteCount && shouldPlay;
} }
@Override @Override

@ -42,7 +42,8 @@ public class QueueManager implements Consumer<Song>
{ {
jukeboxQueue.add(t); jukeboxQueue.add(t);
handler.playNext(); if (!handler.isPlaying())
handler.playNext();
} }
/** /**

Loading…
Cancel
Save