Skip to content

Commit

Permalink
Fix detection of current window index in CastPlayer
Browse files Browse the repository at this point in the history
Issue:#5955
PiperOrigin-RevId: 251616118
  • Loading branch information
AquilesCanta authored and ojw28 committed Jun 6, 2019
1 parent e4feaa6 commit 8bd2b5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
* Fix bug caused by parallel adaptive track selection using `Format`s without
bitrate information
([#5971](https://github.com/google/ExoPlayer/issues/5971)).
* Fix bug in `CastPlayer.getCurrentWindowIndex()`
([#5955](https://github.com/google/ExoPlayer/issues/5955)).

### 2.10.1 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,17 @@ public void updateInternalState() {
notificationsBatch.add(
new ListenerNotificationTask(listener -> listener.onRepeatModeChanged(this.repeatMode)));
}
int currentWindowIndex = fetchCurrentWindowIndex(getMediaStatus());
maybeUpdateTimelineAndNotify();

int currentWindowIndex = C.INDEX_UNSET;
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) {
this.currentWindowIndex = currentWindowIndex;
notificationsBatch.add(
Expand All @@ -565,7 +575,6 @@ public void updateInternalState() {
new ListenerNotificationTask(
listener -> listener.onTracksChanged(currentTrackGroups, currentTrackSelection)));
}
maybeUpdateTimelineAndNotify();
flushNotifications();
}

Expand Down Expand Up @@ -715,16 +724,6 @@ private static int fetchRepeatMode(RemoteMediaClient remoteMediaClient) {
}
}

/**
* Retrieves the current item index from {@code mediaStatus} and maps it into a window index. If
* there is no media session, returns 0.
*/
private static int fetchCurrentWindowIndex(@Nullable MediaStatus mediaStatus) {
Integer currentItemId = mediaStatus != null
? mediaStatus.getIndexById(mediaStatus.getCurrentItemId()) : null;
return currentItemId != null ? currentItemId : 0;
}

private static boolean isTrackActive(long id, long[] activeTrackIds) {
for (long activeTrackId : activeTrackIds) {
if (activeTrackId == id) {
Expand Down

0 comments on commit 8bd2b5b

Please sign in to comment.