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