45 Commits

Author SHA1 Message Date
ibaker
92a6cc10a4 Mark some unreleased IntDefs as TYPE_USE only
The longer list of targets is only necessary for backwards
compatibility with existing Kotlin code that will stop compiling
if the position of the annotation becomes 'wrong' by marking it only
TYPE_USE. Since none of these IntDefs have been released (except in
media3 alpha1) we don't need to maintain this compatibility.

Also add a comment to all the places that *do* need the longer list of
targets, in order to explain why it's there and discourage copy-pasting
when defining new IntDefs in future.

Also fix some single-element arrays to remove the array notation.

#minor-release

PiperOrigin-RevId: 426108537
2022-02-04 09:38:55 +00:00
olly
3871396070 Update session translations
PiperOrigin-RevId: 425589473
2022-02-01 14:34:19 +00:00
christosts
a26d7b821c Rename MediaNotificationHandler to MediaNotificationManager
PiperOrigin-RevId: 425359015
2022-02-01 14:15:22 +00:00
olly
78411006df Fix some additional lint warnings
PiperOrigin-RevId: 424584225
2022-01-28 08:52:11 +00:00
olly
d2cc14a98b Fix some lint warnings
PiperOrigin-RevId: 424383900
2022-01-28 08:46:46 +00:00
olly
9a664d8279 Remove additional translations
PiperOrigin-RevId: 423852067
2022-01-25 19:19:37 +00:00
olly
f8de54e4a5 Replace use of AssertionError in non-test code
PiperOrigin-RevId: 423324890
2022-01-25 19:12:27 +00:00
bachinger
491ac8f066 Estimate content position when playWhenReady never has changed
This change closes an edge case when an app is connecting a controller to a session that is already playing. In such a case `MediaControllerImplBase.getContentPosition()` keeps returning the first estimation for every call until `playWhenReady` changes for the first time.

Reproduction: Launch the demo-session app and start audio playback. Put the activity to the background and then to the foreground again. Go to the playlist view and `PlayerActivity` without interrupting playback and try to seek in the timebar. The position is stuck and snaps back.
PiperOrigin-RevId: 422795360
2022-01-25 18:56:14 +00:00
jaewan
9f2f33657f Fix missing notification of session service release
PiperOrigin-RevId: 422352302
2022-01-25 18:39:54 +00:00
jaewan
86fdbd6f6b Only unsubscribe from specified parentId
PiperOrigin-RevId: 422331961
2022-01-25 18:35:46 +00:00
jaewan
3c8a2c4e2e Stop using vector drawable on Notification for API<21
This fixes flaky failure when posting notification,
although why it's not crashing 100% is unknown.

PiperOrigin-RevId: 422168452
2022-01-25 18:28:08 +00:00
jaewan
e95b15100b Use MediaController to control sessions
This is a small refactoring toward merging
MediaNotificationHandler and PlayerNotificationManager

In detail, this CL includes following changes:
  - Use MediaController to dispatch commands to sessions in
    MediaSessionService, rather than media key events.
  - Use MediaController to monitor changes in MediaSession's
    underlying Player, rather than ForegroundServiceEventCallback.
    Removed the callback interface as well.

PiperOrigin-RevId: 422049265
2022-01-25 18:25:46 +00:00
jaewan
7756d9823d Fix NPE in MediaController's constructor
MediaController tries to release itself when the binder to the
session becomes unavailable. However, if such thing happens while
connecting in the constructor, it causes NPE when accessing
MediaControllerImpl which is only initialized after it's
connected.

This fixes random failures in existing tests.

PiperOrigin-RevId: 421423381
2022-01-25 18:00:42 +00:00
olly
e06b15506c MediaSessionService: Add missing addSession call
PiperOrigin-RevId: 420285295
2022-01-11 13:36:23 +00:00
jaewan
bb81c4969d Fix missing notification of session release
A session may not notify its release back to the controller
when the controller is connecting while the session is releasing.
Here are issues in detail:
  - MediaSession doesn't respond to controller's connection
    request when it's released.
  - MediaSession discards incoming connection requests when it's
    released. The requests are only kept in the application
    looper, but the looper is cleared when the session is
    released.

This CL fixes the above issues, and fixes some flaky tests.

PiperOrigin-RevId: 419756158
2022-01-05 12:15:35 +00:00
jaewan
b440b0fc03 Take MediaSession for building notification
PiperOrigin-RevId: 418154077
2022-01-05 12:14:58 +00:00
christosts
036a28b292 MediaController: stop advancing content position when player is paused
MediaController.getContentPosition() estimates the content position
based on the last position info sent by the player and the elapsed
real-time since the position info was received. After calling
MediaController's play/pause/setPlayWhenReady, the position estimation
logic is still applying, therefore advancing the position until the
underlying player's actual position is received. This can make the
MediaController's content position to be out of sync with player's
actual content position.

With this change, MediaController stops making content position
estimations after any of play/pause/setPlayWhenReady is called and
until a new position info is received from the underlying player.

Tested manually with the the session demo app, pausing/resuming content
from the UI.

PiperOrigin-RevId: 418000800
2022-01-05 12:14:58 +00:00
ibaker
1c3cf6938e Add explicit protected keywords to fields in MediaControllerImplBase
The whole class is package-private, so this is a no-op, but it makes the
intent of the visibililty more clear.

PiperOrigin-RevId: 417377659
2022-01-05 10:36:39 +00:00
jaewan
df2e37acbe Utilize CommandButton for customizing Notification
PiperOrigin-RevId: 416421456
2022-01-05 10:19:09 +00:00
jaewan
8c837c6e2d Clean up resources
PiperOrigin-RevId: 415937814
2022-01-05 09:54:40 +00:00
jaewan
6bceec3246 Remove setters for showing actions in Notification
PiperOrigin-RevId: 414441471
2021-12-07 17:37:31 +00:00
olly
e765f7a8eb Further media3 session cleanup
* Remove casting getInstance and getCallback methods and just
  use member variables that have the more specific types. I
  didn't manage to get rid of casting completely; there are
  still one-off casts during construction. We should look at
  removing those in the future, but it's not completely
  trivial due to the way the Impl classes back-reference
  their wrapping classes.
* Move all callback invocations inside the Impl classes for
  consistency, and properly encapsulate the callbacks there.
  Sticking with the "OnHandler" naming convention for these
  methods, but we should probably tweak that in a subsequent
  change.
* Encapsulate MediaItemFiller in MediaSessionImpl.
* Some misc cleanup (e.g., converting anonymous inner classes
  to lambdas where possible).

PiperOrigin-RevId: 414401978
2021-12-07 17:37:31 +00:00
olly
e59e15d29d Flatten Library and Session service impls
PiperOrigin-RevId: 414396999
2021-12-07 17:37:31 +00:00
jaewan
21bbdb5871 Remove built-in support for stop() in Notification
PiperOrigin-RevId: 414321900
2021-12-07 17:37:31 +00:00
olly
b9f0592702 Remove interfaces that don't seem to serve a purpose
PiperOrigin-RevId: 413966081
2021-12-07 17:37:07 +00:00
olly
f4989f5de1 Forward callback invocations to MediaLibrarySessionImpl
This is required for correct subscription notifications, as per the
referenced bug. It also just seems better to plumb things this way
in general, rather than re-implementing the functionality in the stub.

PiperOrigin-RevId: 413963824
2021-12-07 17:37:07 +00:00
olly
41a2f9a6b3 Simplify threading for media3 session callbacks
This change removes the requirement that callback implementations
need to be able to handle two specific callbacks being called on
two different threads.

PiperOrigin-RevId: 413958545
2021-12-07 17:37:07 +00:00
bachinger
2a62a5ee30 Make setMediaItemFiller public in MediaSession.Builder
#minor-release
Issue: androidx/media#8
PiperOrigin-RevId: 412403132
2021-12-02 11:55:44 +00:00
ibaker
363c9a98ae Remove statically initialized SessionResult
SessionResult stores SystemClock.elapsedRealtime() into
this.completionTimeMs, so a statically initialized instance will have
a meaningless value.

PiperOrigin-RevId: 407865809
2021-11-09 10:10:10 +00:00
ibaker
05c7a30bd7 Fix test-only visibility of MediaController#timeDiffMs
PiperOrigin-RevId: 407787258
2021-11-09 10:10:10 +00:00
ibaker
043a80a5ba Fix most IntDef violations in MediaControllerImplLegacy
This commit doesn't resolve all the violations. Specifically,
INDEX_UNSET is still being incorrectly passed as various IntDef values
to the PlayerInfo constructor, but making these parameters (and the
corresponding PlayerInfo fields) @Nullable is a more involved change
(and it's not obvious at what point we can guarantee the value will be
non-null/non-INDEX_UNSET), so it's left for a later commit.

PiperOrigin-RevId: 407294091
2021-11-09 10:09:13 +00:00
ibaker
8b34d160dc Fix implementations of MediaLibrarySessionCallback to pass params
The documentation makes it clear this value should be propagated
through to the result.

PiperOrigin-RevId: 407085751
2021-11-09 10:09:12 +00:00
ibaker
dfb87e2161 Throw unsupported exception from deprecated MediaController methods
This is consistent with existing deprecated methods that have never been
supported on MediaController.

PiperOrigin-RevId: 407071712
2021-11-09 10:09:12 +00:00
ibaker
686f2ca96d Migrate usages of Window-based Player methods
Where this introduced an inconsistency (e.g. assigning to something
called `windowIndex`), I generally renamed the transitive closure of
identifiers to maintain consistency (meaning this change is quite
large). The exception is code that interacts with Timeline and Window
directly, where sometimes I kept the 'window' nomenclature.

#minor-release

PiperOrigin-RevId: 407040052
2021-11-09 10:07:30 +00:00
ibaker
15e2a13ea3 Re-position IntDefs in media3 stable API
These IntDefs are now annotated with TYPE_USE [1], so they can be moved
to directly before the type (int).

[1] Since https://github.com/androidx/media/commit/9ba21a75f

PiperOrigin-RevId: 406803555
2021-11-09 10:07:00 +00:00
ibaker
b3c8c2a06c Add TYPE_USE to IntDefs used in the media3 stable API
This allows the use of the intdef in parameterized types,
e.g. List<@MyIntDef Integer>

For IntDefs that are already released in ExoPlayer 2.15.1 we add
TYPE_USE in addition to all other reasonable targets, to maintain
backwards compatibility with Kotlin code (where an incorrectly
positioned annotation is a compilation failure). 'reasonable targets'
includes FIELD, METHOD, PARAMETER and LOCAL_VARIABLE but not TYPE,
CONSTRUCTOR, ANNOTATION_TYPE, PACKAGE or MODULE. TYPE_PARAMETER is
implied by TYPE_USE.

For not-yet-released IntDefs we just add TYPE_USE.

#minor-release

PiperOrigin-RevId: 406793413
2021-11-09 10:07:00 +00:00
ibaker
729b2b64f3 Don't pass deviceVolume as volume in MediaControllerImplLegacy
deviceVolume (int) and volume (float) are not the same. Elsewhere
MediaControllerImplLegacy doesn't support volume and defaults to 1
(setVolume, getVolume), so defaulting to 1 here seems correct.

PiperOrigin-RevId: 406780391
2021-11-09 10:07:00 +00:00
ibaker
0d144366c3 Mark MediaSessionService.MediaNotification final
PiperOrigin-RevId: 406347510
2021-11-09 10:07:00 +00:00
ibaker
a60843ead5 Migrate callers of deprecated C.java methods to Util.java
#minor-release

PiperOrigin-RevId: 406166670
2021-11-08 15:17:26 +00:00
ibaker
67640dff0e Remove confusing @throws clauses from MediaLibrarySessionCallback
These seem to be describing an exception being thrown based on a
property of the value being returned from this method? Or is the
expectation that every implementation of this interface throws the
AssertionError themselves.

Given AssertionError is unchecked, and shouldn't be explicitly caught
anywhere, it seems easiest just to remove all this documentation?

PiperOrigin-RevId: 406107606
2021-11-08 15:16:11 +00:00
ibaker
f37e980018 Migrate media3.session references from Window to MediaItem
#minor-release

PiperOrigin-RevId: 405927299
2021-11-08 15:13:41 +00:00
ibaker
d83fe03d88 Update most Player parameter & doc references from Window to MediaItem
Only deprecated references remain.

Usages of the deprecated methods will be migrated in a follow-up change.

#minor-release

PiperOrigin-RevId: 405927141
2021-11-08 15:12:32 +00:00
ibaker
60a68f8891 Remove IntRange from Player.getMediaItemAt
No other index-related methods in Player are annotated, it's considered
obvious that these should be >=0.

PiperOrigin-RevId: 405882756
2021-10-27 17:50:41 +01:00
ibaker
9a49a9ccda Remove all references to @NonNull
Our package-info.java files are annotated with @NonNullApi which results
in everything being non-null by default, so this annotation is never
needed.

#minor-release

PiperOrigin-RevId: 405864737
2021-10-27 17:48:40 +01:00
Andrew Lewis
933e207b3e Update to androidx.media3
PiperOrigin-RevId: 405656499
2021-10-27 09:12:46 +01:00