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);
}
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));
}
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());
}
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());
}
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());
}
Aggregations