Search in sources :

Example 1 with PlaceholderMediaSource

use of org.schabi.newpipe.player.mediasource.PlaceholderMediaSource in project NewPipe by TeamNewPipe.

the class MediaSourceManager method maybeRenewCurrentIndex.

/**
 * Checks if the current playing index contains an expired {@link ManagedMediaSource}.
 * If so, the expired source is replaced by a {@link PlaceholderMediaSource} and
 * {@link #loadImmediate()} is called to reload the current item.
 * <br><br>
 * If not, then the media source at the current index is ready for playback, and
 * {@link #maybeSynchronizePlayer()} is called.
 * <br><br>
 * Under both cases, {@link #maybeSync()} will be called to ensure the listener
 * is up-to-date.
 */
private void maybeRenewCurrentIndex() {
    final int currentIndex = playQueue.getIndex();
    if (sources.getSize() <= currentIndex)
        return;
    final ManagedMediaSource currentSource = (ManagedMediaSource) sources.getMediaSource(currentIndex);
    final PlayQueueItem currentItem = playQueue.getItem();
    if (!currentSource.shouldBeReplacedWith(currentItem, /*canInterruptOnRenew=*/
    true)) {
        maybeSynchronizePlayer();
        return;
    }
    if (DEBUG)
        Log.d(TAG, "MediaSource - Reloading currently playing, " + "index=[" + currentIndex + "], item=[" + currentItem.getTitle() + "]");
    update(currentIndex, new PlaceholderMediaSource(), this::loadImmediate);
}
Also used : PlayQueueItem(org.schabi.newpipe.playlist.PlayQueueItem) PlaceholderMediaSource(org.schabi.newpipe.player.mediasource.PlaceholderMediaSource) ManagedMediaSource(org.schabi.newpipe.player.mediasource.ManagedMediaSource)

Aggregations

ManagedMediaSource (org.schabi.newpipe.player.mediasource.ManagedMediaSource)1 PlaceholderMediaSource (org.schabi.newpipe.player.mediasource.PlaceholderMediaSource)1 PlayQueueItem (org.schabi.newpipe.playlist.PlayQueueItem)1