Search in sources :

Example 1 with FunctionalResultHandler

use of com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler in project lavaplayer by sedmelluq.

the class LocalPlayerDemo method main.

public static void main(String[] args) throws LineUnavailableException, IOException {
    AudioPlayerManager manager = new DefaultAudioPlayerManager();
    AudioSourceManagers.registerRemoteSources(manager);
    manager.getConfiguration().setOutputFormat(new AudioDataFormat(2, 44100, 960, AudioDataFormat.Codec.PCM_S16_BE));
    AudioPlayer player = manager.createPlayer();
    manager.loadItem("ytsearch: epic soundtracks", new FunctionalResultHandler(null, playlist -> {
        player.playTrack(playlist.getTracks().get(0));
    }, null, null));
    AudioDataFormat format = manager.getConfiguration().getOutputFormat();
    AudioInputStream stream = AudioPlayerInputStream.createStream(player, format, 10000L, false);
    SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat());
    SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
    line.open(stream.getFormat());
    line.start();
    byte[] buffer = new byte[format.bufferSize(2)];
    int chunkSize;
    while ((chunkSize = stream.read(buffer)) >= 0) {
        line.write(buffer, 0, chunkSize);
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) LineUnavailableException(javax.sound.sampled.LineUnavailableException) IOException(java.io.IOException) DataLine(javax.sound.sampled.DataLine) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) AudioPlayerInputStream(com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat) AudioSystem(javax.sound.sampled.AudioSystem) FunctionalResultHandler(com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler) SourceDataLine(javax.sound.sampled.SourceDataLine) AudioInputStream(javax.sound.sampled.AudioInputStream) AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) SourceDataLine(javax.sound.sampled.SourceDataLine) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) FunctionalResultHandler(com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)

Aggregations

AudioDataFormat (com.sedmelluq.discord.lavaplayer.format.AudioDataFormat)1 AudioPlayerInputStream (com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream)1 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)1 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)1 FunctionalResultHandler (com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler)1 AudioSourceManagers (com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers)1 IOException (java.io.IOException)1 AudioInputStream (javax.sound.sampled.AudioInputStream)1 AudioSystem (javax.sound.sampled.AudioSystem)1 DataLine (javax.sound.sampled.DataLine)1 LineUnavailableException (javax.sound.sampled.LineUnavailableException)1 SourceDataLine (javax.sound.sampled.SourceDataLine)1