🐛 fix queue
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m40s

This commit is contained in:
Melaine Gérard 2024-12-24 15:03:04 +01:00
parent 7fce86174f
commit c112781ee6
No known key found for this signature in database
GPG Key ID: 89A9588EB2726A53

View File

@ -1,5 +1,8 @@
package org.camelia.studio.kiss.shot.acerola.audio; 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.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
@ -7,19 +10,35 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
public class TrackScheduler extends AudioEventAdapter { public class TrackScheduler extends AudioEventAdapter {
private final AudioPlayer player; private final AudioPlayer player;
private final Queue<AudioTrack> queue;
public TrackScheduler(AudioPlayer player) { public TrackScheduler(AudioPlayer player) {
this.player = player; this.player = player;
this.queue = new LinkedList<>();
} }
public void queue(AudioTrack track) { public void queue(AudioTrack track) {
player.startTrack(track, false); if (!player.startTrack(track, true)) {
queue.offer(track);
}
} }
@Override @Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
if (endReason.mayStartNext) { 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<AudioTrack> getQueue() {
return queue;
}
public void clearQueue() {
queue.clear();
}
} }