From 4fd7d777b669f6adacc3737a7e15b04a57f030fb 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. PiperOrigin-RevId: 391776305 --- RELEASENOTES.md | 6 ++++++ .../com/google/android/exoplayer2/ForwardingPlayer.java | 5 +++++ .../android/exoplayer2/ui/StyledPlayerControlView.java | 3 +++ 3 files changed, 14 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b5a922f3d07..0cb7293bfcb 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,11 @@ # Release notes +### dev-v2 (not yet released) + +* Core Library: + * Fix track selection in `StyledPlayerControlView` when using + `ForwardingPlayer`. + ### 2.15.0 (2021-08-10) * Core Library: 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 1fb0db881bf..d67c7ed50a0 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 @@ -615,6 +615,11 @@ public void setDeviceMuted(boolean muted) { 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 8a4b6ae9a9d..0edfdee634b 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 @@ -757,6 +757,9 @@ public void setPlayer(@Nullable Player player) { 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) {