use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project PorkBot by DaMatrix.
the class AudioUtils method loadAndPlay.
public static void loadAndPlay(final TextChannel channel, final String trackUrl, final Member user, final boolean notify) {
GuildAudioInfo musicManager = getGuildAudioPlayer(channel.getGuild(), true, user, channel);
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
if (notify)
channel.sendMessage("Adding to queue: " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track, user, channel);
synchronized (trackUrl) {
trackUrl.notifyAll();
}
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (tracks == null || tracks.size() == 0) {
channel.sendMessage("Empty or invalid playlist, not loading");
}
if (notify)
channel.sendMessage("Adding " + tracks.size() + " tracks from playlist " + playlist.getName() + " to queue").queue();
playList(channel.getGuild(), musicManager, tracks, user, channel);
synchronized (trackUrl) {
trackUrl.notifyAll();
}
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + trackUrl).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project BoltBot by DiscordBolt.
the class NowPlayingCommand method nowPlayingCommand.
@BotCommand(command = "nowplaying", aliases = { "np", "current", "playing" }, module = MusicModule.MODULE, description = "View what is currently playing", usage = "NowPlaying", allowedChannels = "music")
public static void nowPlayingCommand(CommandContext cc) throws CommandException {
AudioTrack at = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
if (at == null)
throw new CommandStateException("Nothing is currently playing. Play something with !Play");
IMessage nowPlayingMessage = cc.replyWith(MusicModule.createPlayingEmbed(cc.getGuild(), MusicModule.getVoiceManager().getNowPlaying(cc.getGuild())));
ChannelUtil.addReaction(nowPlayingMessage, new Emoji[] { EmojiManager.getForAlias(":black_right_pointing_double_triangle_with_vertical_bar:"), EmojiManager.getForAlias(":star:") });
MusicModule.getVoiceManager().putNowPlayingMessage(nowPlayingMessage, MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()));
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project BoltBot by DiscordBolt.
the class QueueCommand method queueCommand.
@BotCommand(command = "queue", module = MusicModule.MODULE, description = "Show the currently queued songs", usage = "Queue", allowedChannels = "music", args = 1)
public static void queueCommand(CommandContext cc) throws CommandException {
List<AudioTrack> queue = MusicModule.getVoiceManager().getQueue(cc.getGuild());
AudioTrack nowPlaying = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
if (nowPlaying == null)
throw new CommandStateException("The queue is empty! Play something with !Play");
final long totalTime = MusicModule.getVoiceManager().getQueue(cc.getGuild()).stream().map(AudioTrack::getDuration).reduce(0L, (x, y) -> x + y) + MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()).getDuration();
EmbedBuilder embed = new EmbedBuilder();
embed.withTitle(":clock1030: Queue Length");
embed.withDescription(TimeUtil.getFormattedTime(totalTime));
embed.withColor(MusicModule.EMBED_COLOR);
StringBuilder songs = new StringBuilder();
int i = 2;
songs.append("***1. ").append(nowPlaying.getInfo().title).append("***").append('\n');
for (AudioTrack audioTrack : queue) {
if ((songs.length() + audioTrack.getInfo().title.length()) >= 975 && (i - 1) < queue.size()) {
songs.append("\n");
songs.append(" ***... and ").append(queue.size() - (i - 1)).append(" more***");
break;
}
songs.append(i++).append(". ").append(audioTrack.getInfo().title).append('\n');
}
embed.appendField(":arrow_forward: Now Playing", songs.length() > 1 ? songs.toString() : "\n", true);
cc.replyWith(embed.build());
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project BoltBot by DiscordBolt.
the class VoiceManager method getSongTitle.
public String getSongTitle(String songURL) {
Semaphore s = new Semaphore(0);
Info title = new Info();
playerManager.loadItem(songURL, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
title.title = track.getInfo().title;
s.release();
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
s.release();
}
@Override
public void noMatches() {
s.release();
}
@Override
public void loadFailed(FriendlyException exception) {
s.release();
}
});
s.acquireUninterruptibly();
return title.title;
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project DiscLoader by R3alCl0ud.
the class Main method testVoiceThings.
public static CompletableFuture<Void> testVoiceThings(IGuild guild, IChannelCategory category) {
CompletableFuture<Void> future = new CompletableFuture<>();
CompletableFuture<IGuildVoiceChannel> f13 = category.createVoiceChannel("voice-channel");
f13.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(13);
return null;
});
f13.thenAcceptAsync(voicechannel -> {
AvoidRateLimits();
CompletableFuture<VoiceConnection> f14 = voicechannel.join();
f14.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(14);
return null;
});
f14.thenAcceptAsync(voiceconnection -> {
voiceconnection.addListener(new VoiceEventAdapter() {
@Override
public void end(AudioTrack track, AudioTrackEndReason endReason) {
logger.info("Track Finished Playing");
if (endReason == AudioTrackEndReason.LOAD_FAILED) {
logger.severe("Test Failed\nFailed to load the audio track.");
System.exit(15);
return;
}
CompletableFuture<VoiceConnection> f16 = voiceconnection.disconnect();
f16.exceptionally(ex -> {
logger.severe("Test Failed");
ex.printStackTrace();
System.exit(16);
return null;
});
f16.thenAcceptAsync(vc -> {
logger.config("Disconnected From VC");
future.complete(null);
});
}
});
voiceconnection.play("./audio_test.wav");
});
});
return future;
}
Aggregations