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());
}
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);
}
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);
}
Aggregations