Search in sources :

Example 1 with TrackEndEvent

use of com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent 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 2 with TrackEndEvent

use of com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent 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 3 with TrackEndEvent

use of com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent in project lavaplayer by sedmelluq.

the class AudioPlayer method handleTerminator.

private void handleTerminator(InternalAudioTrack track) {
    synchronized (trackSwitchLock) {
        if (activeTrack == track) {
            activeTrack = null;
            dispatchEvent(new TrackEndEvent(this, track, track.getActiveExecutor().failedBeforeLoad() ? LOAD_FAILED : FINISHED));
        }
    }
}
Also used : TrackEndEvent(com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent)

Aggregations

TrackEndEvent (com.sedmelluq.discord.lavaplayer.player.event.TrackEndEvent)3 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)2 TrackStartEvent (com.sedmelluq.discord.lavaplayer.player.event.TrackStartEvent)1