use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class MusicController method addTrack.
private void addTrack(final Message message, final String identifier, final boolean now) {
outputChannel.set((TextChannel) message.getChannel());
manager.loadItemOrdered(this, identifier, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
connectToFirstVoiceChannel(guild.getAudioManager());
message.getChannel().sendMessage("Starting now: " + track.getInfo().title + " (length " + track.getDuration() + ")").queue();
if (now) {
scheduler.playNow(track, true);
} else {
scheduler.addToQueue(track);
}
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
message.getChannel().sendMessage("Loaded playlist: " + playlist.getName() + " (" + tracks.size() + ")").queue();
connectToFirstVoiceChannel(guild.getAudioManager());
AudioTrack selected = playlist.getSelectedTrack();
if (selected != null) {
message.getChannel().sendMessage("Selected track from playlist: " + selected.getInfo().title).queue();
} else {
selected = tracks.get(0);
message.getChannel().sendMessage("Added first track from playlist: " + selected.getInfo().title).queue();
}
if (now) {
scheduler.playNow(selected, true);
} else {
scheduler.addToQueue(selected);
}
for (int i = 0; i < Math.min(10, playlist.getTracks().size()); i++) {
if (tracks.get(i) != selected) {
scheduler.addToQueue(tracks.get(i));
}
}
}
@Override
public void noMatches() {
message.getChannel().sendMessage("Nothing found for " + identifier).queue();
}
@Override
public void loadFailed(FriendlyException throwable) {
message.getChannel().sendMessage("Failed with message: " + throwable.getMessage() + " (" + throwable.getClass().getSimpleName() + ")").queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class MusicController method serialize.
@BotCommandHandler
private void serialize(Message message) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MessageOutput outputStream = new MessageOutput(baos);
for (AudioTrack track : scheduler.drainQueue()) {
manager.encodeTrack(outputStream, track);
}
outputStream.finish();
message.getChannel().sendMessage(Base64.encodeBytes(baos.toByteArray())).queue();
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class MusicController method buildReportForNode.
private String buildReportForNode(RemoteNode node) {
StringBuilder builder = new StringBuilder();
builder.append("--- ").append(node.getAddress()).append(" ---\n");
builder.append("Connection state: ").append(node.getConnectionState()).append("\n");
NodeStatisticsMessage statistics = node.getLastStatistics();
builder.append("Node global statistics: \n").append(statistics == null ? "unavailable" : "");
if (statistics != null) {
builder.append(" playing tracks: ").append(statistics.playingTrackCount).append("\n");
builder.append(" total tracks: ").append(statistics.totalTrackCount).append("\n");
builder.append(" system CPU usage: ").append(statistics.systemCpuUsage).append("\n");
builder.append(" process CPU usage: ").append(statistics.processCpuUsage).append("\n");
}
builder.append("Minimum tick interval: ").append(node.getTickMinimumInterval()).append("\n");
builder.append("Tick history capacity: ").append(node.getTickHistoryCapacity()).append("\n");
List<RemoteNode.Tick> ticks = node.getLastTicks(false);
builder.append("Number of ticks in history: ").append(ticks.size()).append("\n");
if (ticks.size() > 0) {
int tail = Math.min(ticks.size(), 3);
builder.append("Last ").append(tail).append(" ticks:\n");
for (int i = ticks.size() - tail; i < ticks.size(); i++) {
RemoteNode.Tick tick = ticks.get(i);
builder.append(" [duration ").append(tick.endTime - tick.startTime).append("]\n");
builder.append(" start time: ").append(tick.startTime).append("\n");
builder.append(" end time: ").append(tick.endTime).append("\n");
builder.append(" response code: ").append(tick.responseCode).append("\n");
builder.append(" request size: ").append(tick.requestSize).append("\n");
builder.append(" response size: ").append(tick.responseSize).append("\n");
}
}
List<AudioTrack> tracks = node.getPlayingTracks();
builder.append("Number of playing tracks: ").append(tracks.size()).append("\n");
if (tracks.size() > 0) {
int head = Math.min(tracks.size(), 3);
builder.append("First ").append(head).append(" tracks:\n");
for (int i = 0; i < head; i++) {
AudioTrack track = tracks.get(i);
builder.append(" [identifier ").append(track.getInfo().identifier).append("]\n");
builder.append(" name: ").append(track.getInfo().author).append(" - ").append(track.getInfo().title).append("\n");
builder.append(" progress: ").append(track.getPosition()).append(" / ").append(track.getDuration()).append("\n");
}
}
builder.append("Balancer penalties: ").append(tracks.size()).append("\n");
for (Map.Entry<String, Integer> penalty : node.getBalancerPenaltyDetails().entrySet()) {
builder.append(" ").append(penalty.getKey()).append(": ").append(penalty.getValue()).append("\n");
}
return builder.toString();
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.
the class PlayerManagerTestTools method loadTrack.
public static AudioTrack loadTrack(AudioPlayerManager manager, String identifier) throws Exception {
CompletableFuture<AudioTrack> result = new CompletableFuture<>();
manager.loadItem(identifier, new FunctionalResultHandler(result::complete, (playlist) -> result.completeExceptionally(new IllegalArgumentException()), () -> result.completeExceptionally(new NoSuchElementException()), result::completeExceptionally));
return result.get(10, TimeUnit.SECONDS);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Rubicon by Rubicon-Bot.
the class MusicManager method loadSong.
public void loadSong(boolean force) {
TextChannel textChannel = parsedCommandInvocation.getMessage().getTextChannel();
boolean isURL = false;
StringBuilder searchParam = new StringBuilder();
for (int i = 0; i < args.length; i++) searchParam.append(args[i]);
if (searchParam.toString().startsWith("http://") || searchParam.toString().startsWith("https://"))
isURL = true;
if (!isURL)
searchParam.insert(0, "ytsearch: ");
final EmbedBuilder embedBuilder = new EmbedBuilder();
final boolean isURLFinal = isURL;
playerManager.loadItemOrdered(getCurrentMusicManager(), searchParam.toString(), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack audioTrack) {
String trackName = audioTrack.getInfo().title;
String trackAuthor = audioTrack.getInfo().author;
String trackURL = audioTrack.getInfo().uri;
boolean isStream = audioTrack.getInfo().isStream;
long trackDuration = audioTrack.getDuration();
if (!force) {
getCurrentMusicManager().getScheduler().queue(audioTrack);
embedBuilder.setAuthor("Added a new song to queue", trackURL, null);
embedBuilder.addField("Title", trackName, true);
embedBuilder.addField("Author", trackAuthor, true);
embedBuilder.addField("Duration", (isStream) ? "Stream" : getTimestamp(trackDuration), false);
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
}
}
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
AudioTrack firstTrack = audioPlaylist.getSelectedTrack();
List<AudioTrack> playlistTracks = audioPlaylist.getTracks();
playlistTracks = playlistTracks.stream().limit(QUEUE_MAXIMUM - getCurrentMusicManager().getScheduler().getQueue().size()).collect(Collectors.toList());
if (firstTrack == null)
firstTrack = playlistTracks.get(0);
if (force) {
getCurrentMusicManager().getPlayer().playTrack(firstTrack);
return;
}
if (isURLFinal) {
playlistTracks.forEach(getCurrentMusicManager().getScheduler()::queue);
embedBuilder.setTitle("Added playlist to queue");
embedBuilder.setDescription("Added `" + playlistTracks.size() + "` songs from `" + audioPlaylist.getName() + "` to queue.\n" + "\n" + "**Now playing** `" + firstTrack.getInfo().title + "`");
embedBuilder.addField("Author", firstTrack.getInfo().author, true);
embedBuilder.addField("Duration", (firstTrack.getInfo().isStream) ? "Stream" : getTimestamp(firstTrack.getDuration()), false);
textChannel.sendMessage(embedBuilder.build()).queue();
embedBuilder.setColor(Colors.COLOR_PRIMARY);
textChannel.sendMessage(embedBuilder.build()).queue();
} else {
MusicSearchResult musicSearchResult = new MusicSearchResult(parsedCommandInvocation.getAuthor(), guild, getCurrentMusicManager());
audioPlaylist.getTracks().stream().limit(5).collect(Collectors.toList()).forEach(track -> {
try {
musicSearchResult.addTrack(track);
} catch (Exception e) {
e.printStackTrace();
}
});
musicSearchResult.setMessage(textChannel.sendMessage(musicSearchResult.generateEmbed().build()).complete());
musicChoose.add(musicSearchResult);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
if (musicChoose.contains(musicSearchResult)) {
musicSearchResult.getMessage().delete().queue();
musicChoose.remove(musicSearchResult);
}
}
}, 15000);
}
}
@Override
public void noMatches() {
embedBuilder.setTitle("No matches!");
embedBuilder.setDescription("There are no matches.");
embedBuilder.setColor(Colors.COLOR_NOT_IMPLEMENTED);
textChannel.sendMessage(embedBuilder.build()).queue();
}
@Override
public void loadFailed(FriendlyException e) {
embedBuilder.setTitle(":warning: Error!");
embedBuilder.setDescription("Could not play this song: " + e.getMessage());
embedBuilder.setColor(Colors.COLOR_ERROR);
textChannel.sendMessage(embedBuilder.build()).queue();
}
});
}
Aggregations