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
This commit is contained in:
kimvde 2021-08-19 17:27:18 +01:00 committed by Christos Tsilopoulos
parent 64002f6b9a
commit 4fd7d777b6
3 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,11 @@
# Release notes # Release notes
### dev-v2 (not yet released)
* Core Library:
* Fix track selection in `StyledPlayerControlView` when using
`ForwardingPlayer`.
### 2.15.0 (2021-08-10) ### 2.15.0 (2021-08-10)
* Core Library: * Core Library:

View File

@ -615,6 +615,11 @@ public class ForwardingPlayer implements Player {
player.setDeviceMuted(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. @SuppressWarnings("deprecation") // Use of deprecated type for backwards compatibility.
private static class ForwardingEventListener implements EventListener { private static class ForwardingEventListener implements EventListener {

View File

@ -757,6 +757,9 @@ public class StyledPlayerControlView extends FrameLayout {
if (player != null) { if (player != null) {
player.addListener(componentListener); player.addListener(componentListener);
} }
if (player instanceof ForwardingPlayer) {
player = ((ForwardingPlayer) player).getWrappedPlayer();
}
if (player instanceof ExoPlayer) { if (player instanceof ExoPlayer) {
TrackSelector trackSelector = ((ExoPlayer) player).getTrackSelector(); TrackSelector trackSelector = ((ExoPlayer) player).getTrackSelector();
if (trackSelector instanceof DefaultTrackSelector) { if (trackSelector instanceof DefaultTrackSelector) {