mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
83d7a3c1f4
commit
41672c80e7
2 changed files with 32 additions and 11 deletions
|
|
@ -46,6 +46,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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -633,15 +633,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(
|
||||||
|
|
@ -705,7 +697,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;
|
||||||
|
|
@ -714,7 +708,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. */
|
||||||
|
|
@ -924,6 +922,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) {
|
||||||
|
|
@ -1062,6 +1078,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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue