🐛 fix queue
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m40s
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m40s
This commit is contained in:
parent
7fce86174f
commit
c112781ee6
@ -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<AudioTrack> 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<AudioTrack> getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
public void clearQueue() {
|
||||
queue.clear();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user