Search in sources :

Example 1 with TrackStartResponseMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage 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 TrackStartResponseMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method handleResponseBody.

private boolean handleResponseBody(InputStream inputStream, TickBuilder tickBuilder) {
    CountingInputStream countingStream = new CountingInputStream(inputStream);
    DataInputStream input = new DataInputStream(countingStream);
    RemoteMessage message;
    try {
        while ((message = mapper.decode(input)) != null) {
            if (message instanceof TrackStartResponseMessage) {
                handleTrackStartResponse((TrackStartResponseMessage) message);
            } else if (message instanceof TrackFrameDataMessage) {
                handleTrackFrameData((TrackFrameDataMessage) message);
            } else if (message instanceof TrackExceptionMessage) {
                handleTrackException((TrackExceptionMessage) message);
            } else if (message instanceof NodeStatisticsMessage) {
                handleNodeStatistics((NodeStatisticsMessage) message);
            }
        }
    } catch (InterruptedException interruption) {
        log.error("Node {} processing thread was interrupted.", nodeAddress);
        Thread.currentThread().interrupt();
        return false;
    } catch (Throwable e) {
        log.error("Error when processing response from node {}.", nodeAddress, e);
        ExceptionTools.rethrowErrors(e);
    } finally {
        tickBuilder.responseSize = countingStream.getCount();
    }
    return true;
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) TrackExceptionMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage) TrackStartResponseMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DataInputStream(java.io.DataInputStream) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Aggregations

TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)2 MessageHandler (com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)1 NodeStatisticsMessage (com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)1 RemoteMessage (com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage)1 TrackExceptionMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage)1 TrackFrameDataMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage)1 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)1 DataInputStream (java.io.DataInputStream)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1