Search in sources :

Example 21 with AudioTrack

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();
        }
    });
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) List(java.util.List) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 22 with AudioTrack

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()));
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Example 23 with AudioTrack

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());
}
Also used : CommandException(com.discordbolt.api.command.exceptions.CommandException) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) TimeUtil(com.discordbolt.boltbot.utils.TimeUtil) MusicModule(com.discordbolt.boltbot.modules.music.MusicModule) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) CommandContext(com.discordbolt.api.command.CommandContext) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Example 24 with AudioTrack

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;
}
Also used : AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Semaphore(java.util.concurrent.Semaphore) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 25 with AudioTrack

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Options(io.discloader.discloader.common.start.Options) Gson(com.google.gson.Gson) RichEmbed(io.discloader.discloader.core.entity.message.embed.RichEmbed) DiscLoader(io.discloader.discloader.common.DiscLoader) DLLogger(io.discloader.discloader.common.logger.DLLogger) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) IGuild(io.discloader.discloader.entity.guild.IGuild) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel) IUser(io.discloader.discloader.entity.user.IUser) Files(java.nio.file.Files) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) IOException(java.io.IOException) Logger(java.util.logging.Logger) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) IGuildTextChannel(io.discloader.discloader.entity.channel.IGuildTextChannel) Paths(java.nio.file.Paths) CommandRegistry(io.discloader.discloader.common.registry.CommandRegistry) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) IChannelCategory(io.discloader.discloader.entity.channel.IChannelCategory) IMessage(io.discloader.discloader.entity.message.IMessage) DLOptions(io.discloader.discloader.common.DLOptions) VoiceConnection(io.discloader.discloader.entity.voice.VoiceConnection) CompletableFuture(java.util.concurrent.CompletableFuture) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) VoiceEventAdapter(io.discloader.discloader.entity.voice.VoiceEventAdapter) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) IGuildVoiceChannel(io.discloader.discloader.entity.channel.IGuildVoiceChannel)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)85 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)26 ArrayList (java.util.ArrayList)23 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)21 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)18 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)11 List (java.util.List)10 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)9 IOException (java.io.IOException)9 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)8 TimeUnit (java.util.concurrent.TimeUnit)7 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)6 Optional (java.util.Optional)6 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)6 Permission (net.dv8tion.jda.core.Permission)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)5 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)5 Slf4j (lombok.extern.slf4j.Slf4j)5