Search in sources :

Example 1 with InternalAudioTrack

use of com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack 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 InternalAudioTrack

use of com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack in project lavaplayer by sedmelluq.

the class AudioPlayer method startTrack.

/**
 * @param track The track to start playing, passing null will stop the current track and return false
 * @param noInterrupt Whether to only start if nothing else is playing
 * @return True if the track was started
 */
public boolean startTrack(AudioTrack track, boolean noInterrupt) {
    InternalAudioTrack newTrack = (InternalAudioTrack) track;
    InternalAudioTrack previousTrack;
    synchronized (trackSwitchLock) {
        previousTrack = activeTrack;
        if (noInterrupt && previousTrack != null) {
            return false;
        }
        activeTrack = newTrack;
        lastRequestTime = System.currentTimeMillis();
        lastReceiveTime = System.nanoTime();
        stuckEventSent = false;
        if (previousTrack != null) {
            previousTrack.stop();
            dispatchEvent(new TrackEndEvent(this, previousTrack, newTrack == null ? STOPPED : REPLACED));
            shadowTrack = previousTrack;
        }
    }
    if (newTrack == null) {
        shadowTrack = null;
        return false;
    }
    dispatchEvent(new TrackStartEvent(this, newTrack));
    manager.executeTrack(this, newTrack, manager.getConfiguration(), options);
    return true;
}
Also used : TrackStartEvent(com.sedmelluq.discord.lavaplayer.player.event.TrackStartEvent) TrackEndEvent(com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent) InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)

Example 3 with InternalAudioTrack

use of com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack in project lavaplayer by sedmelluq.

the class AudioPlayer method stopWithReason.

private void stopWithReason(AudioTrackEndReason reason) {
    shadowTrack = null;
    synchronized (trackSwitchLock) {
        InternalAudioTrack previousTrack = activeTrack;
        activeTrack = null;
        if (previousTrack != null) {
            previousTrack.stop();
            dispatchEvent(new TrackEndEvent(this, previousTrack, reason));
        }
    }
}
Also used : TrackEndEvent(com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent) InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)

Example 4 with InternalAudioTrack

use of com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack in project lavaplayer by sedmelluq.

the class AudioPlayer method provideDirectly.

/**
 * Provide an audio frame bypassing hooks.
 * @param timeout Specifies the maximum time to wait for data. Pass 0 for non-blocking mode.
 * @param unit Specifies the time unit of the maximum wait time.
 * @return An audio frame if available, otherwise null
 */
public AudioFrame provideDirectly(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
    InternalAudioTrack track;
    lastRequestTime = System.currentTimeMillis();
    if (timeout == 0 && paused.get()) {
        return null;
    }
    while ((track = activeTrack) != null) {
        AudioFrame frame = timeout > 0 ? track.provide(timeout, unit) : track.provide();
        if (frame != null) {
            lastReceiveTime = System.nanoTime();
            shadowTrack = null;
            if (frame.isTerminator()) {
                handleTerminator(track);
                continue;
            }
        } else if (timeout == 0) {
            checkStuck(track);
            frame = provideShadowFrame();
        }
        return frame;
    }
    return null;
}
Also used : InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)

Example 5 with InternalAudioTrack

use of com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack in project lavaplayer by sedmelluq.

the class AudioPlayer method provideShadowFrame.

private AudioFrame provideShadowFrame() {
    InternalAudioTrack shadow = shadowTrack;
    AudioFrame frame = null;
    if (shadow != null) {
        frame = shadow.provide();
        if (frame != null && frame.isTerminator()) {
            shadowTrack = null;
            frame = null;
        }
    }
    return frame;
}
Also used : InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) AudioFrame(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)

Aggregations

InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)5 TrackEndEvent (com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent)2 AudioFrame (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame)2 MessageHandler (com.sedmelluq.discord.lavaplayer.node.message.MessageHandler)1 TrackStartEvent (com.sedmelluq.discord.lavaplayer.player.event.TrackStartEvent)1 TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)1