Search in sources :

Example 1 with RemoveEvent

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

the class PlayQueue method remove.

/**
 * Removes the item at the given index from the play queue.
 *
 * The current playing index will decrement if it is greater than the index being removed.
 * On cases where the current playing index exceeds the playlist range, it is set to 0.
 *
 * Will emit a {@link RemoveEvent} if the index is within the play queue index range.
 */
public synchronized void remove(final int index) {
    if (index >= streams.size() || index < 0)
        return;
    removeInternal(index);
    broadcast(new RemoveEvent(index, getIndex()));
}
Also used : RemoveEvent(org.schabi.newpipe.playlist.events.RemoveEvent)

Example 2 with RemoveEvent

use of org.schabi.newpipe.playlist.events.RemoveEvent 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 RemoveEvent

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

the class PlayQueueAdapter method onPlayQueueChanged.

private void onPlayQueueChanged(final PlayQueueEvent message) {
    switch(message.type()) {
        case RECOVERY:
            // Do nothing.
            break;
        case SELECT:
            final SelectEvent selectEvent = (SelectEvent) message;
            notifyItemChanged(selectEvent.getOldIndex());
            notifyItemChanged(selectEvent.getNewIndex());
            break;
        case APPEND:
            final AppendEvent appendEvent = (AppendEvent) message;
            notifyItemRangeInserted(playQueue.size(), appendEvent.getAmount());
            break;
        case ERROR:
            final ErrorEvent errorEvent = (ErrorEvent) message;
            if (!errorEvent.isSkippable()) {
                notifyItemRemoved(errorEvent.getErrorIndex());
            }
            notifyItemChanged(errorEvent.getErrorIndex());
            notifyItemChanged(errorEvent.getQueueIndex());
            break;
        case REMOVE:
            final RemoveEvent removeEvent = (RemoveEvent) message;
            notifyItemRemoved(removeEvent.getRemoveIndex());
            notifyItemChanged(removeEvent.getQueueIndex());
            break;
        case MOVE:
            final MoveEvent moveEvent = (MoveEvent) message;
            notifyItemMoved(moveEvent.getFromIndex(), moveEvent.getToIndex());
            break;
        case INIT:
        case REORDER:
        default:
            notifyDataSetChanged();
            break;
    }
}
Also used : ErrorEvent(org.schabi.newpipe.playlist.events.ErrorEvent) RemoveEvent(org.schabi.newpipe.playlist.events.RemoveEvent) SelectEvent(org.schabi.newpipe.playlist.events.SelectEvent) MoveEvent(org.schabi.newpipe.playlist.events.MoveEvent) AppendEvent(org.schabi.newpipe.playlist.events.AppendEvent)

Aggregations

RemoveEvent (org.schabi.newpipe.playlist.events.RemoveEvent)3 MoveEvent (org.schabi.newpipe.playlist.events.MoveEvent)2 AppendEvent (org.schabi.newpipe.playlist.events.AppendEvent)1 ErrorEvent (org.schabi.newpipe.playlist.events.ErrorEvent)1 ReorderEvent (org.schabi.newpipe.playlist.events.ReorderEvent)1 SelectEvent (org.schabi.newpipe.playlist.events.SelectEvent)1