Fix recursive loop when registering controller visibility listeners

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: androidx/media#229

#minor-release

PiperOrigin-RevId: 496876397
This commit is contained in:
ibaker 2022-12-21 10:58:36 +00:00 committed by Tianyi Feng
parent 6c98f238e4
commit 4087a011e2
2 changed files with 13 additions and 6 deletions

View File

@ -28,6 +28,11 @@ Release notes
`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.

View File

@ -887,8 +887,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
/**
* 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.
@ -896,14 +896,16 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@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.
*/
@ -923,8 +925,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
this.legacyControllerVisibilityListener = listener;
if (listener != null) {
controller.addVisibilityListener(listener);
setControllerVisibilityListener((ControllerVisibilityListener) null);
}
setControllerVisibilityListener((ControllerVisibilityListener) null);
}
/**