Fix the echo command
This commit is contained in:
parent
569852042c
commit
c53e8164f1
1 changed files with 34 additions and 9 deletions
|
|
@ -20,14 +20,18 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||||
import net.dv8tion.jda.api.audio.AudioReceiveHandler;
|
import net.dv8tion.jda.api.audio.AudioReceiveHandler;
|
||||||
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
||||||
|
import net.dv8tion.jda.api.audio.CombinedAudio;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHandler {
|
public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHandler {
|
||||||
|
|
||||||
private final AudioPlayer audioPlayer;
|
private final AudioPlayer audioPlayer;
|
||||||
private AudioFrame lastFrame;
|
private AudioFrame lastFrame;
|
||||||
|
private final Queue<byte[]> queue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
|
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
|
||||||
this.audioPlayer = audioPlayer;
|
this.audioPlayer = audioPlayer;
|
||||||
|
|
@ -35,28 +39,49 @@ public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHan
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvide() {
|
public boolean canProvide() {
|
||||||
if (lastFrame == null) {
|
if (audioPlayer.getPlayingTrack() == null)
|
||||||
|
return !queue.isEmpty();
|
||||||
|
else if (lastFrame == null) {
|
||||||
lastFrame = audioPlayer.provide();
|
lastFrame = audioPlayer.provide();
|
||||||
|
return lastFrame != null;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return lastFrame != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer provide20MsAudio() {
|
public ByteBuffer provide20MsAudio() {
|
||||||
if (lastFrame == null) {
|
if (audioPlayer.getPlayingTrack() == null) {
|
||||||
lastFrame = audioPlayer.provide();
|
byte[] data = queue.poll();
|
||||||
|
return data == null ? null : ByteBuffer.wrap(data);
|
||||||
|
} else {
|
||||||
|
if (lastFrame == null) {
|
||||||
|
lastFrame = audioPlayer.provide();
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = lastFrame != null ? lastFrame.getData() : null;
|
||||||
|
lastFrame = null;
|
||||||
|
|
||||||
|
return ByteBuffer.wrap(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
byte[] data = lastFrame != null ? lastFrame.getData() : null;
|
@Override
|
||||||
lastFrame = null;
|
public boolean canReceiveCombined() {
|
||||||
|
return queue.size() < 10;
|
||||||
|
}
|
||||||
|
|
||||||
return ByteBuffer.wrap(data);
|
@Override
|
||||||
|
public void handleCombinedAudio(CombinedAudio combinedAudio) {
|
||||||
|
if (combinedAudio.getUsers().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
byte[] data = combinedAudio.getAudioData(1.0f);
|
||||||
|
queue.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpus() {
|
public boolean isOpus() {
|
||||||
return true;
|
return audioPlayer.getPlayingTrack() != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue