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);
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations