aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/soundchan/TrackScheduler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/soundchan/TrackScheduler.java')
-rw-r--r--src/main/java/soundchan/TrackScheduler.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/soundchan/TrackScheduler.java b/src/main/java/soundchan/TrackScheduler.java
index 21bb6d4..cc68335 100644
--- a/src/main/java/soundchan/TrackScheduler.java
+++ b/src/main/java/soundchan/TrackScheduler.java
@@ -10,7 +10,9 @@ import com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
/**
@@ -18,14 +20,14 @@ import java.util.concurrent.LinkedBlockingQueue;
*/
public class TrackScheduler extends AudioEventAdapter {
private final AudioPlayer player;
- private final BlockingQueue<AudioTrack> queue;
+ private final BlockingDeque<AudioTrack> queue;
/**
* @param player The audio player this scheduler uses
*/
public TrackScheduler(AudioPlayer player) {
this.player = player;
- this.queue = new LinkedBlockingQueue<>();
+ this.queue = new LinkedBlockingDeque<>();
}
/**
@@ -42,6 +44,20 @@ public class TrackScheduler extends AudioEventAdapter {
}
}
+ public void playNow(AudioTrack track) {
+ AudioTrack currenlyPlaying = player.getPlayingTrack();
+ AudioTrack cloned = currenlyPlaying.makeClone();
+ cloned.setPosition(currenlyPlaying.getPosition());
+
+ // Don't re-enqueue if its just a soundclip
+ if(!(currenlyPlaying.getInfo().uri.contains(".mp3") || currenlyPlaying.getInfo().uri.contains(".wav")))
+ // Re-enqueue the track
+ queue.addFirst(cloned);
+
+ player.startTrack(track, false);
+
+ }
+
public List<String> getQueueContents() {
// Returns a list of the tracks in the queue
Object[] queueInfo = queue.toArray();