diff options
author | Matt Kohls <mattkohls13@gmail.com> | 2018-04-14 15:49:24 -0400 |
---|---|---|
committer | Matt Kohls <mattkohls13@gmail.com> | 2018-04-14 15:49:24 -0400 |
commit | 70f6beee0fb9569e8549752e627929ae506c5e0c (patch) | |
tree | 3786e817b37b0be9ae1a7d2bfc3f5080869bad0d /src/main/java/soundchan/TrackScheduler.java | |
parent | 780705840a868f0b776c9f18832996ea67e70aa3 (diff) | |
parent | e983b51b8c125663d8b1401d559d6b578d8f156d (diff) | |
download | SoundChan-70f6beee0fb9569e8549752e627929ae506c5e0c.tar.gz SoundChan-70f6beee0fb9569e8549752e627929ae506c5e0c.tar.bz2 SoundChan-70f6beee0fb9569e8549752e627929ae506c5e0c.zip |
Merge branch 'master' of https://github.com/bwaggone/SoundChan into feature/add-help
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(); |