From 4ec47df625e1736ce52d8eb9a7bfc7b3e7b0e461 Mon Sep 17 00:00:00 2001 From: Nekojimi Date: Sun, 19 Jun 2022 23:25:20 +0100 Subject: [PATCH] Fix issues with queue not playing. --- src/main/java/moe/nekojimi/chords/Main.java | 1 + .../java/moe/nekojimi/chords/MusicHandler.java | 17 +++++++++++------ .../java/moe/nekojimi/chords/QueueManager.java | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/moe/nekojimi/chords/Main.java b/src/main/java/moe/nekojimi/chords/Main.java index 273a5c0..e281c2f 100644 --- a/src/main/java/moe/nekojimi/chords/Main.java +++ b/src/main/java/moe/nekojimi/chords/Main.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 AudioManager audioManager = guild.getAudioManager(); musicHandler = new MusicHandler(); + queueManager.setHandler(musicHandler); // Create our Send/Receive handler for the audio connection // EchoHandler handler = new EchoHandler(); diff --git a/src/main/java/moe/nekojimi/chords/MusicHandler.java b/src/main/java/moe/nekojimi/chords/MusicHandler.java index 5b447fc..3719cce 100644 --- a/src/main/java/moe/nekojimi/chords/MusicHandler.java +++ b/src/main/java/moe/nekojimi/chords/MusicHandler.java @@ -25,7 +25,7 @@ public class MusicHandler implements AudioSendHandler, Closeable // private final LinkedList songQueue = new LinkedList<>(); // private final Queue queue = new ConcurrentLinkedQueue<>(); private final CircularByteBuffer audioBuffer = new CircularByteBuffer(3840 * 1024); - private boolean playing = true; + private boolean shouldPlay = true; private int byteCount; private boolean arrayErr = false; @@ -121,14 +121,19 @@ public class MusicHandler implements AudioSendHandler, Closeable 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(); - this.playing = playing; + this.shouldPlay = shouldPlay; } @Override @@ -136,7 +141,7 @@ public class MusicHandler implements AudioSendHandler, Closeable { return player != null && player.has(1); // 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 diff --git a/src/main/java/moe/nekojimi/chords/QueueManager.java b/src/main/java/moe/nekojimi/chords/QueueManager.java index 2382ca1..14e46e2 100644 --- a/src/main/java/moe/nekojimi/chords/QueueManager.java +++ b/src/main/java/moe/nekojimi/chords/QueueManager.java @@ -42,7 +42,8 @@ public class QueueManager implements Consumer { jukeboxQueue.add(t); - handler.playNext(); + if (!handler.isPlaying()) + handler.playNext(); } /**