Commit 7d3375c6 by ibaker Committed by christosts

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
(cherry picked from commit 4087a011)
parent bc829695
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
`Subtitle.getEventTime` if a subtitle file contains no cues. `Subtitle.getEventTime` if a subtitle file contains no cues.
* SubRip: Add support for UTF-16 files if they start with a byte order * SubRip: Add support for UTF-16 files if they start with a byte order
mark. 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: * Session:
* Add abstract `SimpleBasePlayer` to help implement the `Player` interface * Add abstract `SimpleBasePlayer` to help implement the `Player` interface
for custom players. for custom players.
......
...@@ -887,8 +887,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider { ...@@ -887,8 +887,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
/** /**
* Sets the {@link PlayerControlView.VisibilityListener}. * Sets the {@link PlayerControlView.VisibilityListener}.
* *
* <p>Removes any listener set by {@link * <p>If {@code listener} is non-null then any listener set by {@link
* #setControllerVisibilityListener(PlayerControlView.VisibilityListener)}. * #setControllerVisibilityListener(PlayerControlView.VisibilityListener)} is removed.
* *
* @param listener The listener to be notified about visibility changes, or null to remove the * @param listener The listener to be notified about visibility changes, or null to remove the
* current listener. * current listener.
...@@ -896,14 +896,16 @@ public class PlayerView extends FrameLayout implements AdViewProvider { ...@@ -896,14 +896,16 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@SuppressWarnings("deprecation") // Clearing the legacy listener. @SuppressWarnings("deprecation") // Clearing the legacy listener.
public void setControllerVisibilityListener(@Nullable ControllerVisibilityListener listener) { public void setControllerVisibilityListener(@Nullable ControllerVisibilityListener listener) {
this.controllerVisibilityListener = listener; this.controllerVisibilityListener = listener;
if (listener != null) {
setControllerVisibilityListener((PlayerControlView.VisibilityListener) null); setControllerVisibilityListener((PlayerControlView.VisibilityListener) null);
} }
}
/** /**
* Sets the {@link PlayerControlView.VisibilityListener}. * Sets the {@link PlayerControlView.VisibilityListener}.
* *
* <p>Removes any listener set by {@link * <p>If {@code listener} is non-null then any listener set by {@link
* #setControllerVisibilityListener(ControllerVisibilityListener)}. * #setControllerVisibilityListener(ControllerVisibilityListener)} is removed.
* *
* @deprecated Use {@link #setControllerVisibilityListener(ControllerVisibilityListener)} instead. * @deprecated Use {@link #setControllerVisibilityListener(ControllerVisibilityListener)} instead.
*/ */
...@@ -923,9 +925,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider { ...@@ -923,9 +925,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
this.legacyControllerVisibilityListener = listener; this.legacyControllerVisibilityListener = listener;
if (listener != null) { if (listener != null) {
controller.addVisibilityListener(listener); controller.addVisibilityListener(listener);
}
setControllerVisibilityListener((ControllerVisibilityListener) null); setControllerVisibilityListener((ControllerVisibilityListener) null);
} }
}
/** /**
* Sets the {@link FullscreenButtonClickListener}. * Sets the {@link FullscreenButtonClickListener}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment