Search in sources :

Example 1 with ReorderEvent

use of org.schabi.newpipe.playlist.events.ReorderEvent in project NewPipe by TeamNewPipe.

the class PlayQueue method unshuffle.

/**
 * Unshuffles the current play queue if a backup play queue exists.
 *
 * This method undoes shuffling and index will be set to the previously playing item if found,
 * otherwise, the index will reset to 0.
 *
 * Will emit a {@link ReorderEvent} if a backup exists.
 */
public synchronized void unshuffle() {
    if (backup == null)
        return;
    final int originIndex = getIndex();
    final PlayQueueItem current = getItem();
    streams.clear();
    streams = backup;
    backup = null;
    final int newIndex = streams.indexOf(current);
    if (newIndex != -1) {
        queueIndex.set(newIndex);
    } else {
        queueIndex.set(0);
    }
    broadcast(new ReorderEvent(originIndex, queueIndex.get()));
}
Also used : ReorderEvent(org.schabi.newpipe.playlist.events.ReorderEvent)

Example 2 with ReorderEvent

use of org.schabi.newpipe.playlist.events.ReorderEvent in project NewPipe by TeamNewPipe.

the class MediaSourceManager method onPlayQueueChanged.

private void onPlayQueueChanged(final PlayQueueEvent event) {
    if (playQueue.isEmpty() && playQueue.isComplete()) {
        playbackListener.onPlaybackShutdown();
        return;
    }
    // Event specific action
    switch(event.type()) {
        case INIT:
        case ERROR:
            maybeBlock();
        case APPEND:
            populateSources();
            break;
        case SELECT:
            maybeRenewCurrentIndex();
            break;
        case REMOVE:
            final RemoveEvent removeEvent = (RemoveEvent) event;
            remove(removeEvent.getRemoveIndex());
            break;
        case MOVE:
            final MoveEvent moveEvent = (MoveEvent) event;
            move(moveEvent.getFromIndex(), moveEvent.getToIndex());
            break;
        case REORDER:
            // Need to move to ensure the playing index from play queue matches that of
            // the source timeline, and then window correction can take care of the rest
            final ReorderEvent reorderEvent = (ReorderEvent) event;
            move(reorderEvent.getFromSelectedIndex(), reorderEvent.getToSelectedIndex());
            break;
        case RECOVERY:
        default:
            break;
    }
    // Loading and Syncing
    switch(event.type()) {
        case INIT:
        case REORDER:
        case ERROR:
        case SELECT:
            // low frequency, critical events
            loadImmediate();
            break;
        case APPEND:
        case REMOVE:
        case MOVE:
        case RECOVERY:
        default:
            // high frequency or noncritical events
            loadDebounced();
            break;
    }
    if (!isPlayQueueReady()) {
        maybeBlock();
        playQueue.fetch();
    }
    playQueueReactor.request(1);
}
Also used : ReorderEvent(org.schabi.newpipe.playlist.events.ReorderEvent) RemoveEvent(org.schabi.newpipe.playlist.events.RemoveEvent) MoveEvent(org.schabi.newpipe.playlist.events.MoveEvent)

Example 3 with ReorderEvent

use of org.schabi.newpipe.playlist.events.ReorderEvent in project NewPipe by TeamNewPipe.

the class PlayQueue method shuffle.

/**
 * Shuffles the current play queue.
 *
 * This method first backs up the existing play queue and item being played.
 * Then a newly shuffled play queue will be generated along with currently
 * playing item placed at the beginning of the queue.
 *
 * Will emit a {@link ReorderEvent} in any context.
 */
public synchronized void shuffle() {
    if (backup == null) {
        backup = new ArrayList<>(streams);
    }
    final int originIndex = getIndex();
    final PlayQueueItem current = getItem();
    Collections.shuffle(streams);
    final int newIndex = streams.indexOf(current);
    if (newIndex != -1) {
        streams.add(0, streams.remove(newIndex));
    }
    queueIndex.set(0);
    broadcast(new ReorderEvent(originIndex, queueIndex.get()));
}
Also used : ReorderEvent(org.schabi.newpipe.playlist.events.ReorderEvent)

Aggregations

ReorderEvent (org.schabi.newpipe.playlist.events.ReorderEvent)3 MoveEvent (org.schabi.newpipe.playlist.events.MoveEvent)1 RemoveEvent (org.schabi.newpipe.playlist.events.RemoveEvent)1