Add methods in TrackSelection to get details about the playback state.

Determine whether a rebuffer occurred and if the playback is paused or resumed.

PiperOrigin-RevId: 342849010
This commit is contained in:
veronicaradu 2020-11-17 14:19:01 +00:00 committed by Ian Baker
parent e4d693ebb9
commit a19941f09c
2 changed files with 55 additions and 22 deletions

View File

@ -724,6 +724,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
handleMediaSourceListInfoRefreshed(timeline);
}
private void notifyTrackSelectionPlayWhenReadyChanged(boolean playWhenReady) {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll();
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) {
trackSelection.onPlayWhenReadyChanged(playWhenReady);
}
}
periodHolder = periodHolder.getNext();
}
}
private void setPlayWhenReadyInternal(
boolean playWhenReady,
@PlaybackSuppressionReason int playbackSuppressionReason,
@ -734,6 +747,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
playbackInfoUpdate.setPlayWhenReadyChangeReason(reason);
playbackInfo = playbackInfo.copyWithPlayWhenReady(playWhenReady, playbackSuppressionReason);
isRebuffering = false;
notifyTrackSelectionPlayWhenReadyChanged(playWhenReady);
if (!shouldPlayWhenReady()) {
stopRenderers();
updatePlaybackPositions();
@ -880,6 +894,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
}
private void notifyTrackSelectionRebuffer() {
MediaPeriodHolder periodHolder = queue.getPlayingPeriod();
while (periodHolder != null) {
TrackSelection[] trackSelections = periodHolder.getTrackSelectorResult().selections.getAll();
for (TrackSelection trackSelection : trackSelections) {
if (trackSelection != null) {
trackSelection.onRebuffer();
}
}
periodHolder = periodHolder.getNext();
}
}
private void doSomeWork() throws ExoPlaybackException, IOException {
long operationStartTimeMs = clock.uptimeMillis();
updatePeriods();
@ -964,6 +991,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
&& !(enabledRendererCount == 0 ? isTimelineReady() : renderersAllowPlayback)) {
isRebuffering = shouldPlayWhenReady();
setState(Player.STATE_BUFFERING);
if (isRebuffering) {
notifyTrackSelectionRebuffer();
}
livePlaybackSpeedControl.notifyRebuffer();
stopRenderers();
}

View File

@ -73,9 +73,7 @@ public interface TrackSelection {
}
}
/**
* Factory for {@link TrackSelection} instances.
*/
/** Factory for {@link TrackSelection} instances. */
interface Factory {
/**
@ -118,16 +116,12 @@ public interface TrackSelection {
*/
void disable();
/**
* Returns the {@link TrackGroup} to which the selected tracks belong.
*/
/** Returns the {@link TrackGroup} to which the selected tracks belong. */
TrackGroup getTrackGroup();
// Static subset of selected tracks.
/**
* Returns the number of tracks in the selection.
*/
/** Returns the number of tracks in the selection. */
int length();
/**
@ -168,28 +162,21 @@ public interface TrackSelection {
// Individual selected track.
/**
* Returns the {@link Format} of the individual selected track.
*/
/** Returns the {@link Format} of the individual selected track. */
Format getSelectedFormat();
/**
* Returns the index in the track group of the individual selected track.
*/
/** Returns the index in the track group of the individual selected track. */
int getSelectedIndexInTrackGroup();
/**
* Returns the index of the selected track.
*/
/** Returns the index of the selected track. */
int getSelectedIndex();
/**
* Returns the reason for the current track selection.
*/
/** Returns the reason for the current track selection. */
int getSelectionReason();
/** Returns optional data associated with the current track selection. */
@Nullable Object getSelectionData();
@Nullable
Object getSelectionData();
// Adaptation.
@ -208,6 +195,22 @@ public interface TrackSelection {
*/
default void onDiscontinuity() {}
/**
* Called to notify when a rebuffer occurred.
*
* <p>A rebuffer is defined to be caused by buffer depletion rather than a user action. Hence this
* method is not called during initial buffering or when buffering as a result of a seek
* operation.
*/
default void onRebuffer() {}
/**
* Called to notify when the playback is paused or resumed.
*
* @param playWhenReady Whether playback will proceed when ready.
*/
default void onPlayWhenReadyChanged(boolean playWhenReady) {}
/**
* Updates the selected track for sources that load media in discrete {@link MediaChunk}s.
*