use of net.robinfriedli.aiode.audio.AudioQueue in project aiode by robinfriedli.
the class RewindAction method doRun.
@Override
public void doRun() {
AudioQueue queue = audioPlayback.getAudioQueue();
if (!queue.isEmpty()) {
if (queue.hasPrevious()) {
queue.reverse();
}
Guild guild = getContext().getGuild();
GuildVoiceState voiceState = getContext().getMember().getVoiceState();
audioManager.startPlayback(guild, voiceState != null ? voiceState.getChannel() : null);
}
}
use of net.robinfriedli.aiode.audio.AudioQueue in project aiode by robinfriedli.
the class SkipAction method doRun.
@Override
public void doRun() {
AudioQueue queue = audioPlayback.getAudioQueue();
if (!queue.isEmpty()) {
Guild guild = getContext().getGuild();
if (queue.hasNext()) {
queue.iterate();
GuildVoiceState voiceState = getContext().getMember().getVoiceState();
audioManager.startPlayback(guild, voiceState != null ? voiceState.getChannel() : null);
} else {
audioPlayback.stop();
queue.reset();
}
}
}
use of net.robinfriedli.aiode.audio.AudioQueue in project aiode by robinfriedli.
the class ClearCommand method doRun.
@Override
public void doRun() {
AudioPlayback playback = Aiode.get().getAudioManager().getPlaybackForGuild(getContext().getGuild());
AudioQueue audioQueue = playback.getAudioQueue();
audioQueue.clear(playback.isPlaying());
}
use of net.robinfriedli.aiode.audio.AudioQueue 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);
}
use of net.robinfriedli.aiode.audio.AudioQueue 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);
}
Aggregations