Search in sources :

Example 1 with AudioPlayerManager

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager in project FredBoat by Frederikam.

the class AudioPlayerManagerConfiguration method preconfiguredAudioPlayerManager.

/**
 * @return a preconfigured AudioPlayerManager, no AudioSourceManagers set
 */
@Bean(destroyMethod = "")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AudioPlayerManager preconfiguredAudioPlayerManager(AppConfig appConfig) {
    AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
    // Patrons and development get higher quality
    AudioConfiguration.ResamplingQuality quality = AudioConfiguration.ResamplingQuality.LOW;
    if (appConfig.isPatronDistribution() || appConfig.isDevDistribution()) {
        quality = AudioConfiguration.ResamplingQuality.MEDIUM;
    }
    playerManager.getConfiguration().setResamplingQuality(quality);
    playerManager.setFrameBufferDuration(1000);
    playerManager.setItemLoaderThreadPoolSize(500);
    return playerManager;
}
Also used : AudioConfiguration(com.sedmelluq.discord.lavaplayer.player.AudioConfiguration) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) Scope(org.springframework.context.annotation.Scope) Bean(org.springframework.context.annotation.Bean)

Example 2 with AudioPlayerManager

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager 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

AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)2 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)2 AudioDataFormat (com.sedmelluq.discord.lavaplayer.format.AudioDataFormat)1 AudioPlayerInputStream (com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream)1 AudioConfiguration (com.sedmelluq.discord.lavaplayer.player.AudioConfiguration)1 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)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 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1