Skip to content

Commit

Permalink
Fix recursive loop when registering controller visibility listeners
Browse files Browse the repository at this point in the history
There are two overloads of this method due to a type 'rename' from
`PlayerControlView.VisibilityListener` to
`PlayerView.ControllerVisibilityListener`. Currently when you call one
overload it passes `null` to the other one (to clear the other listener).
Unfortunately this results in it clearing itself, because it receives
a null call back!

This change tweaks the documentation to clarify that the 'other'
listener is only cleared if you pass a non-null listener in. This solves
the recursive problem, and allows the 'legacy' visibility listener to be
successfully registered.

Issue: #229

#minor-release

PiperOrigin-RevId: 496876397
(cherry picked from commit 4087a01)
  • Loading branch information
icbaker authored and christosts committed Jan 25, 2023
1 parent bc82969 commit 7d3375c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
`Subtitle.getEventTime` if a subtitle file contains no cues.
* SubRip: Add support for UTF-16 files if they start with a byte order
mark.
* UI:
* Fix the deprecated
`PlayerView.setControllerVisibilityListener(PlayerControlView.VisibilityListener)`
to ensure visibility changes are passed to the registered listener
([#229](https://github.com/androidx/media/issues/229)).
* Session:
* Add abstract `SimpleBasePlayer` to help implement the `Player` interface
for custom players.
Expand Down
14 changes: 8 additions & 6 deletions libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -887,23 +887,25 @@ public void setControllerHideDuringAds(boolean controllerHideDuringAds) {
/**
* Sets the {@link PlayerControlView.VisibilityListener}.
*
* <p>Removes any listener set by {@link
* #setControllerVisibilityListener(PlayerControlView.VisibilityListener)}.
* <p>If {@code listener} is non-null then any listener set by {@link
* #setControllerVisibilityListener(PlayerControlView.VisibilityListener)} is removed.
*
* @param listener The listener to be notified about visibility changes, or null to remove the
* current listener.
*/
@SuppressWarnings("deprecation") // Clearing the legacy listener.
public void setControllerVisibilityListener(@Nullable ControllerVisibilityListener listener) {
this.controllerVisibilityListener = listener;
setControllerVisibilityListener((PlayerControlView.VisibilityListener) null);
if (listener != null) {
setControllerVisibilityListener((PlayerControlView.VisibilityListener) null);
}
}

/**
* Sets the {@link PlayerControlView.VisibilityListener}.
*
* <p>Removes any listener set by {@link
* #setControllerVisibilityListener(ControllerVisibilityListener)}.
* <p>If {@code listener} is non-null then any listener set by {@link
* #setControllerVisibilityListener(ControllerVisibilityListener)} is removed.
*
* @deprecated Use {@link #setControllerVisibilityListener(ControllerVisibilityListener)} instead.
*/
Expand All @@ -923,8 +925,8 @@ public void setControllerVisibilityListener(
this.legacyControllerVisibilityListener = listener;
if (listener != null) {
controller.addVisibilityListener(listener);
setControllerVisibilityListener((ControllerVisibilityListener) null);
}
setControllerVisibilityListener((ControllerVisibilityListener) null);
}

/**
Expand Down

0 comments on commit 7d3375c

Please sign in to comment.