diff options
author | Brandon <bwaggone@umich.edu> | 2018-04-14 15:20:23 -0400 |
---|---|---|
committer | Brandon <bwaggone@umich.edu> | 2018-04-14 15:20:23 -0400 |
commit | 97dd68fbbfd28c6c0f42ac06f4d70606990667b4 (patch) | |
tree | a666be81bd6019970123e79bfc50b720490fa8f2 /src/main/java/soundchan/TrackScheduler.java | |
parent | 3bc325f7d249cd25002f32ba8b516c7644d8c506 (diff) | |
download | SoundChan-97dd68fbbfd28c6c0f42ac06f4d70606990667b4.tar.gz SoundChan-97dd68fbbfd28c6c0f42ac06f4d70606990667b4.tar.bz2 SoundChan-97dd68fbbfd28c6c0f42ac06f4d70606990667b4.zip |
Add sound preemption + change structure
Diffstat (limited to 'src/main/java/soundchan/TrackScheduler.java')
-rw-r--r-- | src/main/java/soundchan/TrackScheduler.java | 20 |
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(); |