= Fixed music
This commit is contained in:
@@ -27,7 +27,6 @@ public class CommandMusicMain extends Command
|
|||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
||||||
System.out.println("SCF: " + scf.resString);
|
|
||||||
scf.Call(res);
|
scf.Call(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package commands.music;
|
|
||||||
|
|
||||||
public class MusicThread extends Thread
|
|
||||||
{
|
|
||||||
public MusicThread()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Called when spawned
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package commands.music;
|
package commands.music;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
|
|
||||||
import core.SubCommand;
|
import core.SubCommand;
|
||||||
import core.SubCommandFormattable;
|
import core.SubCommandFormattable;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
@@ -17,8 +21,17 @@ public class SubCommandPlaylist extends SubCommand
|
|||||||
@Override
|
@Override
|
||||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||||
{
|
{
|
||||||
// ArrayList<AudioTrack> playlist = guild.audio.getPlaylist();
|
ArrayList <AudioTrack> playlist = guild.audio.getPlaylist();
|
||||||
String stringPlaylist = guild.audio.getPlaylist(guild.audio.player);
|
String stringPlaylist = "";
|
||||||
|
|
||||||
|
for(AudioTrack track : playlist)
|
||||||
|
{
|
||||||
|
stringPlaylist += (playlist.indexOf(track) + 1) + ": " + track.getInfo().title + "\n";
|
||||||
|
}
|
||||||
|
if(stringPlaylist.equals(""))
|
||||||
|
{
|
||||||
|
return new SubCommandFormattable("Nothing Queued!");
|
||||||
|
}
|
||||||
return new SubCommandFormattable(stringPlaylist);
|
return new SubCommandFormattable(stringPlaylist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class SubCommandStop extends SubCommand
|
|||||||
@Override
|
@Override
|
||||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player));
|
return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package utils.audio;
|
package utils.audio;
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
@@ -21,7 +20,7 @@ public class AudioUtils
|
|||||||
public AudioManager am;
|
public AudioManager am;
|
||||||
public final AudioPlayer player;
|
public final AudioPlayer player;
|
||||||
public final AudioPlayerManager playerManager;
|
public final AudioPlayerManager playerManager;
|
||||||
private Queue <AudioTrack> playlist = new LinkedList<>();
|
private ArrayList <AudioTrack> playlist = new ArrayList<AudioTrack>();
|
||||||
|
|
||||||
|
|
||||||
public AudioUtils(Guild guild, AudioPlayerManager playerManager)
|
public AudioUtils(Guild guild, AudioPlayerManager playerManager)
|
||||||
@@ -86,11 +85,8 @@ public class AudioUtils
|
|||||||
|
|
||||||
public class SmallAudio implements AudioLoadResultHandler
|
public class SmallAudio implements AudioLoadResultHandler
|
||||||
{
|
{
|
||||||
private AudioPlayer player;
|
|
||||||
|
|
||||||
private SmallAudio(AudioPlayer player)
|
private SmallAudio(AudioPlayer player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void loadFailed(FriendlyException arg0) { }
|
@Override public void loadFailed(FriendlyException arg0) { }
|
||||||
@@ -104,14 +100,6 @@ public class AudioUtils
|
|||||||
{
|
{
|
||||||
playlist.add(track);
|
playlist.add(track);
|
||||||
}
|
}
|
||||||
do
|
|
||||||
{
|
|
||||||
if(player.getPlayingTrack() == null)
|
|
||||||
{
|
|
||||||
player.startTrack(playlist.poll(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(!playlist.isEmpty());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,13 +108,21 @@ public class AudioUtils
|
|||||||
{
|
{
|
||||||
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player));
|
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player));
|
||||||
playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player));
|
playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player));
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
if(player.getPlayingTrack() == null)
|
||||||
|
{
|
||||||
|
MusicController control = new MusicController(player, playlist);
|
||||||
|
control.start();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String skipVideo(AudioPlayer player)
|
public String skipVideo(AudioPlayer player)
|
||||||
{
|
{
|
||||||
return null;
|
player.stopTrack();
|
||||||
|
return "Skipped";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String stopPlayer(AudioPlayer player)
|
public String stopPlayer(AudioPlayer player)
|
||||||
@@ -136,13 +132,44 @@ public class AudioUtils
|
|||||||
return "Stopped";
|
return "Stopped";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlaylist(AudioPlayer player)
|
public ArrayList<AudioTrack> getPlaylist()
|
||||||
{
|
{
|
||||||
String response ="";
|
return playlist;
|
||||||
for(AudioTrack track:playlist)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MusicController extends Thread
|
||||||
{
|
{
|
||||||
response += track.getInfo().title;
|
AudioPlayer player;
|
||||||
|
private ArrayList <AudioTrack> playlist;
|
||||||
|
|
||||||
|
public MusicController(AudioPlayer player, ArrayList <AudioTrack> playlist)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.playlist = playlist;
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
AudioTrack nowPlaying = null;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(!playlist.isEmpty() || nowPlaying != null)
|
||||||
|
{
|
||||||
|
if(player.getPlayingTrack() == null)
|
||||||
|
{
|
||||||
|
if(playlist.isEmpty())
|
||||||
|
nowPlaying = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nowPlaying = playlist.get(0);
|
||||||
|
playlist.remove(0);
|
||||||
|
}
|
||||||
|
player.startTrack(nowPlaying, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(!playlist.isEmpty() || player.getPlayingTrack() != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user