Resolve mute bug

This commit is contained in:
Sebastien 2019-09-10 21:26:03 +02:00
parent 7cb4eee1ff
commit a00c054453

View File

@ -2,6 +2,7 @@ package net.Broken.audio;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
import net.dv8tion.jda.api.audio.AudioSendHandler; import net.dv8tion.jda.api.audio.AudioSendHandler;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -13,27 +14,27 @@ import java.nio.ByteBuffer;
*/ */
public class AudioPlayerSendHandler implements AudioSendHandler { public class AudioPlayerSendHandler implements AudioSendHandler {
private final AudioPlayer audioPlayer; private final AudioPlayer audioPlayer;
private AudioFrame lastFrame; private final ByteBuffer buffer;
private final MutableAudioFrame frame;
/** /**
* @param audioPlayer Audio player to wrap. * @param audioPlayer Audio player to wrap.
*/ */
public AudioPlayerSendHandler(AudioPlayer audioPlayer) { public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
this.audioPlayer = audioPlayer; this.audioPlayer = audioPlayer;
this.buffer = ByteBuffer.allocate(1024);
this.frame = new MutableAudioFrame();
this.frame.setBuffer(buffer);
} }
@Override @Override
public boolean canProvide() { public boolean canProvide() {
if (lastFrame == null) { return audioPlayer.provide(frame);
lastFrame = audioPlayer.provide();
}
return lastFrame != null;
} }
@Override @Override
public ByteBuffer provide20MsAudio() { public ByteBuffer provide20MsAudio() {
return ByteBuffer.wrap(lastFrame.getData()); return (ByteBuffer) buffer.flip();
} }
@Override @Override