Search in sources :

Example 1 with MessageHandler

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));
}
Also used : TrackStartResponseMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage) InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) MessageHandler(com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)

Example 2 with MessageHandler

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));
}
Also used : ArrayList(java.util.ArrayList) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame) MessageHandler(com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)

Aggregations

MessageHandler (com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)2 TrackFrameDataMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage)1 TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)1 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)1 AudioFrame (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)1 ArrayList (java.util.ArrayList)1