diff options
author | Brandon <bwaggone@umich.edu> | 2018-04-07 19:18:18 -0400 |
---|---|---|
committer | Brandon <bwaggone@umich.edu> | 2018-04-07 19:18:18 -0400 |
commit | 6d8c86d7683e18cdc62370c479a9db24cc8b100c (patch) | |
tree | 0351977a2a0dbc2f1de2d2cf33d0f8134ce28a11 | |
parent | a7d690c352bb718dfe74368d2973e2798617fc62 (diff) | |
download | SoundChan-6d8c86d7683e18cdc62370c479a9db24cc8b100c.tar.gz SoundChan-6d8c86d7683e18cdc62370c479a9db24cc8b100c.tar.bz2 SoundChan-6d8c86d7683e18cdc62370c479a9db24cc8b100c.zip |
Add list queued support
-rw-r--r-- | src/main/java/soundchan/Main.java | 18 | ||||
-rw-r--r-- | src/main/java/soundchan/TrackScheduler.java | 16 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/soundchan/Main.java b/src/main/java/soundchan/Main.java index 326285f..8b1ccfc 100644 --- a/src/main/java/soundchan/Main.java +++ b/src/main/java/soundchan/Main.java @@ -131,7 +131,11 @@ public class Main extends ListenerAdapter { pauseTrack(channel); } else if ("~unpause".equals(command[0])) { unpauseTrack(channel); - }} + } else if ("~list".equals(command[0])) { + listTracks(channel); + } + + } super.onMessageReceived(event); } @@ -142,6 +146,17 @@ public class Main extends ListenerAdapter { channel.sendMessage("Volume now set to " + volume + "%").queue(); } + private void listTracks(final MessageChannel channel) { + GuildMusicManager musicManager = getGuildAudioPlayer(); + List<String> queueContents = musicManager.scheduler.getQueueContents(); + String printMessage = "Tracks in the queue:\n"; + for (String track: + queueContents) { + printMessage = printMessage + track + "\n"; + } + channel.sendMessage(printMessage).queue(); + } + private void pauseTrack(final MessageChannel channel){ GuildMusicManager musicManager = getGuildAudioPlayer(); musicManager.player.setPaused(true); @@ -163,6 +178,7 @@ public class Main extends ListenerAdapter { int timeStart = trackUrl.lastIndexOf('='); if(timeStart != -1){ String timeString = trackUrl.substring(timeStart); + //The format will be 1h2m53s, need to parse that into seconds and then call //track.setPosition(long position) diff --git a/src/main/java/soundchan/TrackScheduler.java b/src/main/java/soundchan/TrackScheduler.java index 7f1c258..21bb6d4 100644 --- a/src/main/java/soundchan/TrackScheduler.java +++ b/src/main/java/soundchan/TrackScheduler.java @@ -2,9 +2,14 @@ package soundchan; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; +import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason; +import com.sedmelluq.discord.lavaplayer.track.DelegatedAudioTrack; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -37,6 +42,17 @@ public class TrackScheduler extends AudioEventAdapter { } } + public List<String> getQueueContents() { + // Returns a list of the tracks in the queue + Object[] queueInfo = queue.toArray(); + List<String> tracks = new ArrayList<>(); + for (Object item: + queueInfo) { + tracks.add(((DelegatedAudioTrack) item).getInfo().title); + } + return tracks; + } + /** * Start the next track, stopping the current one if it is playing. */ |