From c112781ee67839b008d7aec3b14f66cabaff6a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melaine=20G=C3=A9rard?= Date: Tue, 24 Dec 2024 15:03:04 +0100 Subject: [PATCH] :bug: fix queue --- .../shot/acerola/audio/TrackScheduler.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/TrackScheduler.java b/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/TrackScheduler.java index 46bf097..c358e68 100644 --- a/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/TrackScheduler.java +++ b/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/TrackScheduler.java @@ -1,5 +1,8 @@ package org.camelia.studio.kiss.shot.acerola.audio; +import java.util.LinkedList; +import java.util.Queue; + import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -7,19 +10,35 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; public class TrackScheduler extends AudioEventAdapter { private final AudioPlayer player; + private final Queue queue; public TrackScheduler(AudioPlayer player) { this.player = player; + this.queue = new LinkedList<>(); } public void queue(AudioTrack track) { - player.startTrack(track, false); + if (!player.startTrack(track, true)) { + queue.offer(track); + } } @Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { if (endReason.mayStartNext) { - // Ici vous pouvez gérer la lecture de la prochaine piste si vous implémentez une file d'attente + nextTrack(); } } + + public void nextTrack() { + player.startTrack(queue.poll(), false); + } + + public Queue getQueue() { + return queue; + } + + public void clearQueue() { + queue.clear(); + } } \ No newline at end of file