package de.yannicpunktdee.yoshibot.audio;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import net.dv8tion.jda.api.audio.AudioSendHandler;

import java.nio.ByteBuffer;

public class AudioSendHandlerImpl implements AudioSendHandler {
	
	private final AudioPlayer audioPlayer;
	private AudioFrame lastFrame;
	
	
	public AudioSendHandlerImpl(AudioPlayer audioPlayer) {
		this.audioPlayer = audioPlayer;
	}
	
	//
	@Override
	public boolean canProvide() {
		lastFrame = audioPlayer.provide();
		return lastFrame != null;
	}
	
	@Override
	public ByteBuffer provide20MsAudio() {
		return ByteBuffer.wrap(lastFrame.getData());
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isOpus() {
		return true;
	}
	
}
