Commit a67d260e by kimvde Committed by marcbaechinger

Fix onPositionDiscontinuity event in CastPlayer

- Avoid having two onPositionDiscontinuity events (seek and transition)
  sent after a seek to another media item.
- Avoid triggering an onPositionDiscontinuity event after a timeline
  change.

#minor-release

PiperOrigin-RevId: 361092914
parent db60db70
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
* MediaSession extension: Remove dependency to core module and rely on common * MediaSession extension: Remove dependency to core module and rely on common
only. The `TimelineQueueEditor` uses a new `MediaDescriptionConverter` for only. The `TimelineQueueEditor` uses a new `MediaDescriptionConverter` for
this purpose and does not rely on the `ConcatenatingMediaSource` anymore. this purpose and does not rely on the `ConcatenatingMediaSource` anymore.
* Cast extension:
* Fix `onPositionDiscontinuity` event so that it is not triggered with
reason `DISCONTINUITY_REASON_PERIOD_TRANSITION` after a seek to another
media item and so that it is not triggered after a timeline change.
### 2.13.2 (2021-02-25) ### 2.13.2 (2021-02-25)
......
...@@ -653,15 +653,7 @@ public final class CastPlayer extends BasePlayer { ...@@ -653,15 +653,7 @@ public final class CastPlayer extends BasePlayer {
updateRepeatModeAndNotifyIfChanged(/* resultCallback= */ null); updateRepeatModeAndNotifyIfChanged(/* resultCallback= */ null);
updateTimelineAndNotifyIfChanged(); updateTimelineAndNotifyIfChanged();
int currentWindowIndex = C.INDEX_UNSET; int currentWindowIndex = fetchCurrentWindowIndex(remoteMediaClient, currentTimeline);
MediaQueueItem currentItem = remoteMediaClient.getCurrentItem();
if (currentItem != null) {
currentWindowIndex = currentTimeline.getIndexOfPeriod(currentItem.getItemId());
}
if (currentWindowIndex == C.INDEX_UNSET) {
// The timeline is empty. Fall back to index 0, which is what ExoPlayer would do.
currentWindowIndex = 0;
}
if (this.currentWindowIndex != currentWindowIndex && pendingSeekCount == 0) { if (this.currentWindowIndex != currentWindowIndex && pendingSeekCount == 0) {
this.currentWindowIndex = currentWindowIndex; this.currentWindowIndex = currentWindowIndex;
listeners.queueEvent( listeners.queueEvent(
...@@ -721,7 +713,9 @@ public final class CastPlayer extends BasePlayer { ...@@ -721,7 +713,9 @@ public final class CastPlayer extends BasePlayer {
} }
/** /**
* Updates the current timeline and returns whether it has changed. * Updates the current timeline. The current window index may change as a result.
*
* @return Whether the current timeline has changed.
*/ */
private boolean updateTimeline() { private boolean updateTimeline() {
CastTimeline oldTimeline = currentTimeline; CastTimeline oldTimeline = currentTimeline;
...@@ -730,7 +724,11 @@ public final class CastPlayer extends BasePlayer { ...@@ -730,7 +724,11 @@ public final class CastPlayer extends BasePlayer {
status != null status != null
? timelineTracker.getCastTimeline(remoteMediaClient) ? timelineTracker.getCastTimeline(remoteMediaClient)
: CastTimeline.EMPTY_CAST_TIMELINE; : CastTimeline.EMPTY_CAST_TIMELINE;
return !oldTimeline.equals(currentTimeline); boolean timelineChanged = !oldTimeline.equals(currentTimeline);
if (timelineChanged) {
currentWindowIndex = fetchCurrentWindowIndex(remoteMediaClient, currentTimeline);
}
return timelineChanged;
} }
/** Updates the internal tracks and selection and returns whether they have changed. */ /** Updates the internal tracks and selection and returns whether they have changed. */
...@@ -940,6 +938,24 @@ public final class CastPlayer extends BasePlayer { ...@@ -940,6 +938,24 @@ public final class CastPlayer extends BasePlayer {
} }
} }
private static int fetchCurrentWindowIndex(
@Nullable RemoteMediaClient remoteMediaClient, Timeline timeline) {
if (remoteMediaClient == null) {
return 0;
}
int currentWindowIndex = C.INDEX_UNSET;
@Nullable MediaQueueItem currentItem = remoteMediaClient.getCurrentItem();
if (currentItem != null) {
currentWindowIndex = timeline.getIndexOfPeriod(currentItem.getItemId());
}
if (currentWindowIndex == C.INDEX_UNSET) {
// The timeline is empty. Fall back to index 0, which is what ExoPlayer would do.
currentWindowIndex = 0;
}
return currentWindowIndex;
}
private static boolean isTrackActive(long id, long[] activeTrackIds) { private static boolean isTrackActive(long id, long[] activeTrackIds) {
for (long activeTrackId : activeTrackIds) { for (long activeTrackId : activeTrackIds) {
if (activeTrackId == id) { if (activeTrackId == id) {
...@@ -1078,6 +1094,7 @@ public final class CastPlayer extends BasePlayer { ...@@ -1078,6 +1094,7 @@ public final class CastPlayer extends BasePlayer {
+ CastUtils.getLogString(statusCode)); + CastUtils.getLogString(statusCode));
} }
if (--pendingSeekCount == 0) { if (--pendingSeekCount == 0) {
currentWindowIndex = pendingSeekWindowIndex;
pendingSeekWindowIndex = C.INDEX_UNSET; pendingSeekWindowIndex = C.INDEX_UNSET;
pendingSeekPositionMs = C.TIME_UNSET; pendingSeekPositionMs = C.TIME_UNSET;
listeners.sendEvent(/* eventFlag= */ C.INDEX_UNSET, EventListener::onSeekProcessed); listeners.sendEvent(/* eventFlag= */ C.INDEX_UNSET, EventListener::onSeekProcessed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment