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 net.dv8tion.jda.api.audio.AudioReceiveHandler;
|
||||
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
||||
import net.dv8tion.jda.api.audio.CombinedAudio;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHandler {
|
||||
|
||||
private final AudioPlayer audioPlayer;
|
||||
private AudioFrame lastFrame;
|
||||
private final Queue<byte[]> queue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
|
||||
this.audioPlayer = audioPlayer;
|
||||
|
|
@ -35,16 +39,22 @@ public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHan
|
|||
|
||||
@Override
|
||||
public boolean canProvide() {
|
||||
if (lastFrame == null) {
|
||||
if (audioPlayer.getPlayingTrack() == null)
|
||||
return !queue.isEmpty();
|
||||
else if (lastFrame == null) {
|
||||
lastFrame = audioPlayer.provide();
|
||||
}
|
||||
|
||||
return lastFrame != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ByteBuffer provide20MsAudio() {
|
||||
if (audioPlayer.getPlayingTrack() == null) {
|
||||
byte[] data = queue.poll();
|
||||
return data == null ? null : ByteBuffer.wrap(data);
|
||||
} else {
|
||||
if (lastFrame == null) {
|
||||
lastFrame = audioPlayer.provide();
|
||||
}
|
||||
|
|
@ -54,9 +64,24 @@ public class AudioPlayerSendHandler implements AudioSendHandler, AudioReceiveHan
|
|||
|
||||
return ByteBuffer.wrap(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveCombined() {
|
||||
return queue.size() < 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCombinedAudio(CombinedAudio combinedAudio) {
|
||||
if (combinedAudio.getUsers().isEmpty())
|
||||
return;
|
||||
|
||||
byte[] data = combinedAudio.getAudioData(1.0f);
|
||||
queue.add(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpus() {
|
||||
return true;
|
||||
return audioPlayer.getPlayingTrack() != null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue