diff options
author | Matt <mattkohls13@gmail.com> | 2018-04-14 15:32:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-14 15:32:20 -0400 |
commit | e983b51b8c125663d8b1401d559d6b578d8f156d (patch) | |
tree | 9187e688ad78f9ea1ad104a6c71857e6a24c7985 /src/main/java/soundchan/TrackScheduler.java | |
parent | f8fe02e835c6417a54033b30a66c9c3bc2097836 (diff) | |
parent | 14006737593b80d198f0d19d820a37bd984e8ccc (diff) | |
download | SoundChan-e983b51b8c125663d8b1401d559d6b578d8f156d.tar.gz SoundChan-e983b51b8c125663d8b1401d559d6b578d8f156d.tar.bz2 SoundChan-e983b51b8c125663d8b1401d559d6b578d8f156d.zip |
Merge pull request #5 from bwaggone/feature/preempt-sound-effects
Feature/preempt sound effects
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(); |