Youtube Progress

This commit is contained in:
Alex
2020-01-15 01:51:23 -05:00
parent 46cf6f8c97
commit 3a03793124
2 changed files with 61 additions and 1 deletions
+5 -1
View File
@@ -124,18 +124,21 @@ public class AudioUtils
private void startPlay(AudioPlayer player) private void startPlay(AudioPlayer player)
{ {
isPlaying = false;
do do
{ {
if(player.getPlayingTrack() == null) if(player.getPlayingTrack() == null)
{ {
System.out.println("HERE");
if(playlist.isEmpty()) if(playlist.isEmpty())
{ {
isPlaying = false; isPlaying = false;
} }
else else
{ {
System.out.println("NEXT SONG");
player.startTrack(playlist.get(0), false); player.startTrack(playlist.get(0), false);
isPlaying = true;
if(!playlist.isEmpty()) if(!playlist.isEmpty())
playlist.remove(0); playlist.remove(0);
@@ -152,6 +155,7 @@ public class AudioUtils
try try
{ {
playlist.remove(0); playlist.remove(0);
player.getPlayingTrack();
} }
catch(Exception e) catch(Exception e)
{ {
+56
View File
@@ -0,0 +1,56 @@
package utils.audio;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
/**
* This class schedules tracks for the audio player. It contains the queue of tracks.
*/
public class TrackScheduler extends AudioEventAdapter {
private final AudioPlayer player;
private final BlockingQueue<AudioTrack> queue;
/**
* @param player The audio player this scheduler uses
*/
public TrackScheduler(AudioPlayer player) {
this.player = player;
this.queue = new LinkedBlockingQueue<>();
}
/**
* Add the next track to queue or play right away if nothing is in the queue.
*
* @param track The track to play or add to queue.
*/
public void queue(AudioTrack track)
{
// Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If
// something is playing, it returns false and does nothing. In that case the player was already playing so this
// track goes to the queue instead.
if (!player.startTrack(track, true)) {
queue.offer(track);
}
}
/**
* Start the next track, stopping the current one if it is playing.
*/
public void nextTrack() {
// Start the next track, regardless of if something is already playing or not. In case queue was empty, we are
// giving null to startTrack, which is a valid argument and will simply stop the player.
player.startTrack(queue.poll(), false);
}
@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
if (endReason.mayStartNext) {
nextTrack();
}
}
}