From 1ae879788a932fd54bde0bd3abc5d09573c6789e Mon Sep 17 00:00:00 2001 From: kimvde Date: Thu, 19 Aug 2021 17:27:18 +0100 Subject: [PATCH] Fix issue caused by using ForwardingPlayer and StyledPlayerControlView StyledPlayerControlView was checking whether the player is an ExoPlayer instance to set the track selector. This means that, if apps were wrapping an ExoPlayer in a ForwardingPlayer (to replace a ControlDispatcher for example), the track selector wasn't set anymore. #minor-release PiperOrigin-RevId: 391776305 --- RELEASENOTES.md | 2 ++ .../java/com/google/android/exoplayer2/ForwardingPlayer.java | 5 +++++ .../android/exoplayer2/ui/StyledPlayerControlView.java | 3 +++ 3 files changed, 10 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index bb679bccab..4540f9634c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -9,6 +9,8 @@ `com.google.android.exoplayer2.decoder.CryptoException`. * Make `ExoPlayer.Builder` return a `SimpleExoPlayer` instance. * Deprecate `SimpleExoPlayer.Builder`. Use `ExoPlayer.Builder` instead. + * Fix track selection in `StyledPlayerControlView` when using + `ForwardingPlayer`. * Android 12 compatibility: * Disable platform transcoding when playing content URIs on Android 12. * Add `ExoPlayer.setVideoChangeFrameRateStrategy` to allow disabling of diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java index 59329088f8..f4467a180b 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java @@ -619,6 +619,11 @@ public class ForwardingPlayer implements Player { player.setDeviceMuted(muted); } + /** Returns the {@link Player} to which operations are forwarded. */ + public Player getWrappedPlayer() { + return player; + } + @SuppressWarnings("deprecation") // Use of deprecated type for backwards compatibility. private static class ForwardingEventListener implements EventListener { diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index 45786b1eaa..277faca145 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -756,6 +756,9 @@ public class StyledPlayerControlView extends FrameLayout { if (player != null) { player.addListener(componentListener); } + if (player instanceof ForwardingPlayer) { + player = ((ForwardingPlayer) player).getWrappedPlayer(); + } if (player instanceof ExoPlayer) { TrackSelector trackSelector = ((ExoPlayer) player).getTrackSelector(); if (trackSelector instanceof DefaultTrackSelector) {