Search in sources :

Example 1 with ManagedMediaSource

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

the class MediaSourceManager method isCorrectionNeeded.

/**
 * Checks if the corresponding MediaSource in {@link DynamicConcatenatingMediaSource}
 * for a given {@link PlayQueueItem} needs replacement, either due to gapless playback
 * readiness or playlist desynchronization.
 * <br><br>
 * If the given {@link PlayQueueItem} is currently being played and is already loaded,
 * then correction is not only needed if the playlist is desynchronized. Otherwise, the
 * check depends on the status (e.g. expiration or placeholder) of the
 * {@link ManagedMediaSource}.
 */
private boolean isCorrectionNeeded(@NonNull final PlayQueueItem item) {
    final int index = playQueue.indexOf(item);
    if (index == -1 || index >= sources.getSize())
        return false;
    final ManagedMediaSource mediaSource = (ManagedMediaSource) sources.getMediaSource(index);
    return mediaSource.shouldBeReplacedWith(item, /*mightBeInProgress=*/
    index != playQueue.getIndex());
}
Also used : ManagedMediaSource(org.schabi.newpipe.player.mediasource.ManagedMediaSource)

Example 2 with ManagedMediaSource

use of org.schabi.newpipe.player.mediasource.ManagedMediaSource 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)

Example 3 with ManagedMediaSource

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

the class MediaSourceManager method isPlaybackReady.

private boolean isPlaybackReady() {
    if (sources.getSize() != playQueue.size())
        return false;
    final ManagedMediaSource mediaSource = (ManagedMediaSource) sources.getMediaSource(playQueue.getIndex());
    final PlayQueueItem playQueueItem = playQueue.getItem();
    return mediaSource.isStreamEqual(playQueueItem);
}
Also used : PlayQueueItem(org.schabi.newpipe.playlist.PlayQueueItem) ManagedMediaSource(org.schabi.newpipe.player.mediasource.ManagedMediaSource)

Aggregations

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