Search in sources :

Example 6 with AudioManager

use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.

the class PlayCommand method handleResults.

@Override
protected void handleResults(List<Playable> playables) {
    if (playables.isEmpty()) {
        throw new NoResultsFoundException("Result is empty!");
    }
    Guild guild = getContext().getGuild();
    VoiceChannel channel = getContext().getVoiceChannel();
    AudioManager audioManager = Aiode.get().getAudioManager();
    AudioPlayback playback = getContext().getGuildContext().getPlayback();
    AudioPlayer audioPlayer = playback.getAudioPlayer();
    if (audioPlayer.getPlayingTrack() != null) {
        audioPlayer.stopTrack();
    }
    playback.getAudioQueue().set(playables);
    audioManager.startPlayback(guild, channel);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Example 7 with AudioManager

use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.

the class RewindCommand method doRun.

@Override
public void doRun() {
    AudioManager audioManager = Aiode.get().getAudioManager();
    Guild guild = getContext().getGuild();
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue queue = playback.getAudioQueue();
    VoiceChannel channel = getContext().getVoiceChannel();
    if (!queue.hasPrevious()) {
        throw new InvalidCommandException("No previous item in queue");
    }
    int queueSize = queue.getTracks().size();
    if (getCommandInput().isBlank()) {
        queue.reverse();
    } else {
        int offset;
        try {
            offset = Integer.parseInt(getCommandInput());
        } catch (NumberFormatException e) {
            throw new InvalidCommandException(getCommandInput() + " is not an integer");
        }
        if (offset < 1) {
            throw new InvalidCommandException("Expected a number grater than 0");
        }
        boolean deficient = queue.getPosition() - offset < 0;
        int newIndex;
        if (!playback.isRepeatAll() && deficient) {
            newIndex = 0;
        } else if (deficient) {
            // if the current index is 20 with 50 tracks in the queue and the user wants to rewind 24, the result should be 46
            int provisional = queue.getPosition() - offset;
            int page = provisional / queueSize * (-1) + 1;
            newIndex = page * queueSize + provisional;
        } else {
            newIndex = queue.getPosition() - offset;
        }
        queue.setPosition(newIndex);
    }
    audioManager.startPlayback(guild, channel);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 8 with AudioManager

use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.

the class SkipCommand method doRun.

@Override
public void doRun() {
    AudioManager audioManager = Aiode.get().getAudioManager();
    Guild guild = getContext().getGuild();
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue queue = playback.getAudioQueue();
    VoiceChannel channel = getContext().getVoiceChannel();
    if (!queue.hasNext()) {
        throw new InvalidCommandException("No next item in queue");
    }
    if (getCommandInput().isBlank()) {
        queue.iterate();
    } else {
        int offset;
        try {
            offset = Integer.parseInt(getCommandInput());
        } catch (NumberFormatException e) {
            throw new InvalidCommandException(getCommandInput() + " is not an integer");
        }
        if (offset < 1) {
            throw new InvalidCommandException("Expected a number greater than 0");
        }
        int newIndex;
        int queueSize = queue.getTracks().size();
        boolean overflow = queue.getPosition() + offset >= queueSize;
        if (!playback.isRepeatAll() && overflow) {
            newIndex = queueSize - 1;
        } else if (overflow) {
            // if the current index is 30 with 50 tracks in the queue and the user wants to skip 24, the result should be 4
            // if the user wants to skip 20, the result be 0
            int provisional = queue.getPosition() + offset;
            int page = provisional / queueSize;
            newIndex = provisional - (page * queueSize);
        } else {
            newIndex = queue.getPosition() + offset;
        }
        queue.setPosition(newIndex);
    }
    audioManager.startPlayback(guild, channel);
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 9 with AudioManager

use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.

the class PlayCommand method withUserResponse.

@Override
public void withUserResponse(Object option) {
    AudioManager audioManager = Aiode.get().getAudioManager();
    Guild guild = getContext().getGuild();
    PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), getTrackLoadingExecutor());
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue queue = playback.getAudioQueue();
    List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), option);
    AudioPlayer audioPlayer = playback.getAudioPlayer();
    if (audioPlayer.getPlayingTrack() != null) {
        audioPlayer.stopTrack();
    }
    queue.set(playables);
    audioManager.startPlayback(guild, getContext().getVoiceChannel());
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) Playable(net.robinfriedli.aiode.audio.Playable) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue)

Example 10 with AudioManager

use of net.robinfriedli.aiode.audio.AudioManager in project aiode by robinfriedli.

the class QueueCommand method listQueue.

private void listQueue() {
    Guild guild = getContext().getGuild();
    AudioManager audioManager = Aiode.get().getAudioManager();
    AudioPlayback playback = audioManager.getPlaybackForGuild(guild);
    AudioQueue audioQueue = playback.getAudioQueue();
    CompletableFuture<Message> futureMessage = sendMessage(audioQueue.buildMessageEmbed(playback, guild));
    WidgetRegistry widgetRegistry = getContext().getGuildContext().getWidgetRegistry();
    CompletableFutures.thenAccept(futureMessage, message -> new QueueWidget(widgetRegistry, guild, message, playback).initialise());
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) Message(net.dv8tion.jda.api.entities.Message) WidgetRegistry(net.robinfriedli.aiode.command.widget.WidgetRegistry) Guild(net.dv8tion.jda.api.entities.Guild) AudioQueue(net.robinfriedli.aiode.audio.AudioQueue) QueueWidget(net.robinfriedli.aiode.command.widget.widgets.QueueWidget)

Aggregations

AudioManager (net.robinfriedli.aiode.audio.AudioManager)15 AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)12 Guild (net.dv8tion.jda.api.entities.Guild)9 Playable (net.robinfriedli.aiode.audio.Playable)7 PlayableFactory (net.robinfriedli.aiode.audio.PlayableFactory)7 Aiode (net.robinfriedli.aiode.Aiode)6 CommandContext (net.robinfriedli.aiode.command.CommandContext)6 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)5 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)5 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)5 AudioTrackLoader (net.robinfriedli.aiode.audio.AudioTrackLoader)5 Playlist (net.robinfriedli.aiode.entities.Playlist)5 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)5 Lists (com.google.common.collect.Lists)4 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)4 IOException (java.io.IOException)4 List (java.util.List)4 Callable (java.util.concurrent.Callable)4 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)4 UrlPlayable (net.robinfriedli.aiode.audio.UrlPlayable)4