Search in sources :

Example 6 with AudioPlayback

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

the class PauseCommand method doRun.

@Override
public void doRun() {
    Guild guild = getContext().getGuild();
    AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(guild);
    playback.pause();
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) Guild(net.dv8tion.jda.api.entities.Guild)

Example 7 with AudioPlayback

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

the class PlayCommand method doRun.

@Override
public void doRun() throws Exception {
    CommandContext context = getContext();
    Guild guild = context.getGuild();
    VoiceChannel channel = context.getVoiceChannel();
    AudioManager audioManager = Aiode.get().getAudioManager();
    MessageChannel messageChannel = getContext().getChannel();
    AudioPlayback playbackForGuild = audioManager.getPlaybackForGuild(guild);
    playbackForGuild.setCommunicationChannel(messageChannel);
    if (getCommandInput().isBlank()) {
        if (playbackForGuild.isPaused() || !audioManager.getQueue(guild).isEmpty()) {
            audioManager.startOrResumePlayback(guild, channel);
        } else {
            throw new InvalidCommandException("Queue is empty. Specify a song you want to play.");
        }
    } else {
        super.doRun();
    }
}
Also used : AudioManager(net.robinfriedli.aiode.audio.AudioManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) CommandContext(net.robinfriedli.aiode.command.CommandContext) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Example 8 with AudioPlayback

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

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

the class QueueCommand method handleResults.

@Override
protected void handleResults(List<Playable> playables) {
    if (playables.isEmpty()) {
        throw new NoResultsFoundException("Result is empty!");
    }
    AudioPlayback playback = getContext().getGuildContext().getPlayback();
    playback.getAudioQueue().add(playables);
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException)

Example 10 with AudioPlayback

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

the class ReverseCommand 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 toReverseMs;
    try {
        if (argumentSet("minutes")) {
            toReverseMs = Integer.parseInt(getCommandInput()) * 60000;
        } else {
            toReverseMs = Integer.parseInt(getCommandInput()) * 1000;
        }
    } catch (NumberFormatException e) {
        throw new InvalidCommandException("'" + getCommandInput() + "' is not convertible to type integer. " + "Please enter a valid number.");
    }
    if (toReverseMs <= 0) {
        throw new InvalidCommandException("Expected 1 or greater");
    }
    long newPosition = playback.getCurrentPositionMs() - toReverseMs;
    if (newPosition < 0) {
        throw new InvalidCommandException("New position less than 0");
    }
    playback.setPosition(newPosition);
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

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