Commit 2f8c8b60 by aquilescanta Committed by Oliver Woodman

Fix detection of current window index in CastPlayer

Issue:#5955
PiperOrigin-RevId: 251616118
parent 83a6d51f
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
* Fix bug caused by parallel adaptive track selection using `Format`s without * Fix bug caused by parallel adaptive track selection using `Format`s without
bitrate information bitrate information
([#5971](https://github.com/google/ExoPlayer/issues/5971)). ([#5971](https://github.com/google/ExoPlayer/issues/5971)).
* Fix bug in `CastPlayer.getCurrentWindowIndex()`
([#5955](https://github.com/google/ExoPlayer/issues/5955)).
### 2.10.1 ### ### 2.10.1 ###
......
...@@ -551,7 +551,17 @@ public final class CastPlayer extends BasePlayer { ...@@ -551,7 +551,17 @@ public final class CastPlayer extends BasePlayer {
notificationsBatch.add( notificationsBatch.add(
new ListenerNotificationTask(listener -> listener.onRepeatModeChanged(this.repeatMode))); 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) { if (this.currentWindowIndex != currentWindowIndex && pendingSeekCount == 0) {
this.currentWindowIndex = currentWindowIndex; this.currentWindowIndex = currentWindowIndex;
notificationsBatch.add( notificationsBatch.add(
...@@ -564,7 +574,6 @@ public final class CastPlayer extends BasePlayer { ...@@ -564,7 +574,6 @@ public final class CastPlayer extends BasePlayer {
new ListenerNotificationTask( new ListenerNotificationTask(
listener -> listener.onTracksChanged(currentTrackGroups, currentTrackSelection))); listener -> listener.onTracksChanged(currentTrackGroups, currentTrackSelection)));
} }
maybeUpdateTimelineAndNotify();
flushNotifications(); flushNotifications();
} }
...@@ -714,16 +723,6 @@ public final class CastPlayer extends BasePlayer { ...@@ -714,16 +723,6 @@ public final class CastPlayer extends BasePlayer {
} }
} }
/**
* 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) { private static boolean isTrackActive(long id, long[] activeTrackIds) {
for (long activeTrackId : activeTrackIds) { for (long activeTrackId : activeTrackIds) {
if (activeTrackId == id) { if (activeTrackId == id) {
......
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