Search in sources :

Example 1 with TrackStartEvent

use of com.sedmelluq.discord.lavaplayer.player.event.TrackStartEvent 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)

Aggregations

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