Search in sources :

Example 1 with AudioDataFormat

use of com.sedmelluq.discord.lavaplayer.format.AudioDataFormat in project lavaplayer by sedmelluq.

the class TrackStartRequestCodec method decode.

@Override
public TrackStartRequestMessage decode(DataInput in, int version) throws IOException {
    long executorId = in.readLong();
    AudioTrackInfo trackInfo = new AudioTrackInfo(in.readUTF(), in.readUTF(), in.readLong(), in.readUTF(), in.readBoolean(), null);
    byte[] encodedTrack = new byte[in.readInt()];
    in.readFully(encodedTrack);
    int volume = in.readInt();
    AudioConfiguration configuration = new AudioConfiguration();
    configuration.setResamplingQuality(AudioConfiguration.ResamplingQuality.valueOf(in.readUTF()));
    configuration.setOpusEncodingQuality(in.readInt());
    if (version >= VERSION_WITH_FORMAT) {
        AudioDataFormat format = new AudioDataFormat(in.readInt(), in.readInt(), in.readInt(), AudioDataFormat.Codec.valueOf(in.readUTF()));
        configuration.setOutputFormat(format);
    }
    long position = 0;
    if (version >= VERSION_WITH_POSITION) {
        position = in.readLong();
    }
    return new TrackStartRequestMessage(executorId, trackInfo, encodedTrack, volume, configuration, position);
}
Also used : AudioConfiguration(com.sedmelluq.discord.lavaplayer.player.AudioConfiguration) AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 2 with AudioDataFormat

use of com.sedmelluq.discord.lavaplayer.format.AudioDataFormat 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)

Example 3 with AudioDataFormat

use of com.sedmelluq.discord.lavaplayer.format.AudioDataFormat in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method handleTrackFrameData.

private void handleTrackFrameData(TrackFrameDataMessage message) throws Exception {
    RemoteAudioTrackExecutor executor = playingTracks.get(message.executorId);
    if (executor != null) {
        if (message.seekedPosition >= 0) {
            executor.clearSeek(message.seekedPosition);
        }
        AudioFrameBuffer buffer = executor.getAudioBuffer();
        executor.receivedData();
        AudioDataFormat format = executor.getConfiguration().getOutputFormat();
        for (AudioFrame frame : message.frames) {
            buffer.consume(new AudioFrame(frame.timecode, frame.data, frame.volume, format));
        }
        if (message.finished) {
            buffer.setTerminateOnEmpty();
            trackEnded(executor, false);
        }
    }
}
Also used : AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat) AudioFrameBuffer(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)

Example 4 with AudioDataFormat

use of com.sedmelluq.discord.lavaplayer.format.AudioDataFormat in project lavaplayer by sedmelluq.

the class TrackStartRequestCodec method encode.

@Override
public void encode(DataOutput out, TrackStartRequestMessage message) throws IOException {
    int version = version(message);
    out.writeLong(message.executorId);
    out.writeUTF(message.trackInfo.title);
    out.writeUTF(message.trackInfo.author);
    out.writeLong(message.trackInfo.length);
    out.writeUTF(message.trackInfo.identifier);
    out.writeBoolean(message.trackInfo.isStream);
    out.writeInt(message.encodedTrack.length);
    out.write(message.encodedTrack);
    out.writeInt(message.volume);
    out.writeUTF(message.configuration.getResamplingQuality().name());
    out.writeInt(message.configuration.getOpusEncodingQuality());
    if (version >= VERSION_WITH_FORMAT) {
        AudioDataFormat format = message.configuration.getOutputFormat();
        out.writeInt(format.channelCount);
        out.writeInt(format.sampleRate);
        out.writeInt(format.chunkSampleCount);
        out.writeUTF(format.codec.name());
    }
    if (version >= VERSION_WITH_POSITION) {
        out.writeLong(message.position);
    }
}
Also used : AudioDataFormat(com.sedmelluq.discord.lavaplayer.format.AudioDataFormat)

Aggregations

AudioDataFormat (com.sedmelluq.discord.lavaplayer.format.AudioDataFormat)4 AudioPlayerInputStream (com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream)1 AudioConfiguration (com.sedmelluq.discord.lavaplayer.player.AudioConfiguration)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 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)1 AudioFrame (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)1 AudioFrameBuffer (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer)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