Search in sources :

Example 16 with AudioPlayback

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

the class ForwardCommand method doRun.

@Override
public void doRun() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    AudioTrack playingTrack = playback.getAudioPlayer().getPlayingTrack();
    if (playingTrack == null) {
        throw new InvalidCommandException("No track is being played at the moment");
    }
    long toForwardMs;
    try {
        if (argumentSet("minutes")) {
            toForwardMs = Integer.parseInt(getCommandInput()) * 60000;
        } else {
            toForwardMs = Integer.parseInt(getCommandInput()) * 1000;
        }
    } catch (NumberFormatException e) {
        throw new InvalidCommandException("'" + getCommandInput() + "' is not convertible to type integer. " + "Please enter a valid number.");
    }
    if (toForwardMs <= 0) {
        throw new InvalidCommandException("Expected 1 or greater");
    }
    long newPosition = playback.getCurrentPositionMs() + toForwardMs;
    long duration = playback.getAudioQueue().getCurrent().durationMs();
    if (newPosition > duration) {
        throw new InvalidCommandException("New position too high! Current track duration: " + Util.normalizeMillis(duration) + ", new position: " + Util.normalizeMillis(newPosition));
    }
    playback.setPosition(newPosition);
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 17 with AudioPlayback

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

the class ForwardCommand method onSuccess.

@Override
public void onSuccess() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    long currentPositionMs = playback.getCurrentPositionMs();
    sendSuccess("Set position to " + Util.normalizeMillis(currentPositionMs));
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback)

Example 18 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback 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 19 with AudioPlayback

use of net.robinfriedli.aiode.audio.AudioPlayback 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)

Example 20 with AudioPlayback

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

the class ShuffleCommand method doRun.

@Override
public void doRun() {
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
    playback.setShuffle(!playback.isShuffle());
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback)

Aggregations

AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)25 Guild (net.dv8tion.jda.api.entities.Guild)13 AudioManager (net.robinfriedli.aiode.audio.AudioManager)9 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)7 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)6 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)5 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)4 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 IOException (java.io.IOException)2 LocalDateTime (java.time.LocalDateTime)2 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)2 Aiode (net.robinfriedli.aiode.Aiode)2 Playable (net.robinfriedli.aiode.audio.Playable)2 AccessConfiguration (net.robinfriedli.aiode.entities.AccessConfiguration)2 GuildSpecification (net.robinfriedli.aiode.entities.GuildSpecification)2 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)2 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 OutputStream (java.io.OutputStream)1 Duration (java.time.Duration)1