From 6de6bd9c4f23b87427b7d2c4cb2c330aef5fba49 Mon Sep 17 00:00:00 2001 From: tonihei Date: Mon, 22 May 2023 12:50:07 +0100 Subject: [PATCH] Extend main Player Javadoc The main interface documentation hasn't been updated substantially since 2017 and is missing notes for many of its current features and requirements. Also change the recommendation for implementors from BasePlayer to SimpleBasePlayer to ensure new classes are more likely to cover all of the interface requirements. #minor-release PiperOrigin-RevId: 534027117 --- .../java/androidx/media3/common/Player.java | 127 ++++++++++++++++-- 1 file changed, 113 insertions(+), 14 deletions(-) diff --git a/libraries/common/src/main/java/androidx/media3/common/Player.java b/libraries/common/src/main/java/androidx/media3/common/Player.java index 0b3ee05817..822cb506ef 100644 --- a/libraries/common/src/main/java/androidx/media3/common/Player.java +++ b/libraries/common/src/main/java/androidx/media3/common/Player.java @@ -47,26 +47,125 @@ import java.util.ArrayList; import java.util.List; /** - * A media player interface defining traditional high-level functionality, such as the ability to - * play, pause, seek and query properties of the currently playing media. + * A media player interface defining high-level functionality, such as the ability to play, pause, + * seek and query properties of the currently playing media. * - *

All methods must be called from a single {@linkplain #getApplicationLooper() application - * thread} unless indicated otherwise. Callbacks in registered listeners are called on the same - * thread. - * - *

This interface includes some convenience methods that can be implemented by calling other - * methods in the interface. {@link BasePlayer} implements these convenience methods so inheriting - * {@link BasePlayer} is recommended when implementing the interface so that only the minimal set of - * required methods can be implemented. + *

Player features and usage

* *

Some important properties of media players that implement this interface are: * *

+ * + *

API stability guarantees

+ * + *

The majority of the Player interface and its related classes are part of the stable API that + * guarantees backwards-compatibility for users of the API. Only more advances use cases may need to + * rely on {@link UnstableApi} classes and methods that are subject to incompatible changes or even + * removal in a future release. Implementors of the Player interface are not covered by these API + * stability guarantees. + * + *

Player state

+ * + *

Users can listen to state changes by adding a {@link Player.Listener} with {@link + * #addListener}. + * + *

The main elements of the overall player state are: + * + *

+ * + *

Note that there are no callbacks for normal playback progression, only for {@linkplain + * Listener#onMediaItemTransition transitions between media items} and other {@linkplain + * Listener#onPositionDiscontinuity position discontinuities}. Code that needs to monitor playback + * progress (for example, an UI progress bar) should query the current position in appropriate + * intervals. + * + *

Implementing the Player interface

+ * + *

Implementing the Player interface is complex, as the interface includes many convenience + * methods that need to provide a consistent state and behavior, requires correct handling of + * listeners and available commands, and expects immediate state changes even if methods are + * internally handled asynchronously. For this reason, implementations are advised to inherit {@link + * SimpleBasePlayer} that handles all of these complexities and provides a simpler integration point + * for implementors of the interface. */ public interface Player {