use of com.sedmelluq.discord.lavaplayer.node.message.MessageHandler in project lavaplayer by sedmelluq.
the class PlayingTrackManager method handleTrackStart.
@MessageHandler
private void handleTrackStart(TrackStartRequestMessage message, MessageOutput output) {
InternalAudioTrack audioTrack = (InternalAudioTrack) manager.decodeTrackDetails(message.trackInfo, message.encodedTrack);
String failureReason = null;
if (audioTrack != null) {
if (message.position != 0) {
audioTrack.setPosition(message.position);
}
PlayingTrack playingTrack = new PlayingTrack(message.executorId, message.volume, audioTrack);
PlayingTrack existingTrack = tracks.putIfAbsent(message.executorId, playingTrack);
if (existingTrack == null) {
log.info("Track start request for {} (context {}, position {})", message.trackInfo.identifier, message.executorId, message.position);
manager.executeTrack(playingTrack, audioTrack, message.configuration, playingTrack.volume);
statisticsManager.increaseTrackCount();
} else {
log.info("Start request for an already playing track {} (context {}), applying seek to {} from it.", message.trackInfo.identifier, message.executorId, message.position);
existingTrack.audioTrack.setPosition(message.position);
}
} else {
log.warn("Unable to find a matching source for track {} (context {})", message.trackInfo.identifier, message.executorId);
failureReason = "This node does not support this type of track.";
}
output.send(new TrackStartResponseMessage(message.executorId, failureReason == null, failureReason));
}
use of com.sedmelluq.discord.lavaplayer.node.message.MessageHandler in project lavaplayer by sedmelluq.
the class PlayingTrackManager method handleTrackDataRequest.
@MessageHandler
private void handleTrackDataRequest(TrackFrameRequestMessage message, MessageOutput output) {
List<AudioFrame> frames = new ArrayList<>();
PlayingTrack track = tracks.get(message.executorId);
boolean finished = false;
if (track != null) {
submitPendingMessages(track, output);
track.lastFrameRequestTime = System.currentTimeMillis();
track.volume.set(message.volume);
if (message.seekPosition >= 0) {
track.audioTrack.setPosition(message.seekPosition);
}
if (message.maximumFrames > 0) {
track.lastNonZeroFrameRequestTime = track.lastFrameRequestTime;
}
finished = consumeFramesFromTrack(frames, track.audioTrack, message.maximumFrames);
if (finished) {
log.info("Clearing ended track {} (context {})", track.audioTrack.getIdentifier(), message.executorId);
tracks.remove(message.executorId);
}
}
output.send(new TrackFrameDataMessage(message.executorId, frames, finished, message.seekPosition));
}
Aggregations