47 Commits

Author SHA1 Message Date
bachinger
85a936ecb1 Implement session extras for Media3 and legacy controllers
This provides an (unstable) API for apps to broadcast session extras
Bundle to all connected controllers and set the extras in the legacy
session.

Similar to the custom layout, the extras Bundle is not part of the
Media3 session state. This means that when a Media3 controller
connects to the session after the broadcast, the extras needs to be
sent to that controller in  `MediaSession.Callback.onPostConnect(MediaSession session, ControllerInfo controller)`.

PiperOrigin-RevId: 451871731
2022-05-30 16:52:43 +00:00
bachinger
bf3d81c262 Add missing tests for custom layout notification
PiperOrigin-RevId: 451859199
2022-05-30 16:51:08 +00:00
tonihei
581c6b5429 Remove MediaMetadata.mediaUrl
This value only existed to allow setting media URLs from external sources
(e.g. in a MediaController) so that a player can start playing this item.
Now that we have MediaItem.RequestMetadata.mediaUrl we can remove this value
from MediaMetadata because it's request metadata, not media metadata.

PiperOrigin-RevId: 451857413
2022-05-30 16:49:28 +00:00
tonihei
6b782d1011 Replace MediaItemFiller by asynchronous callback.
The MediaItemFiller is not flexible enough for most realworld usages
because:
 - it doesn't allow asynchronous resolution of MediaItems (e.g. to
   look up URIs from a database)
 - it doesn't allow to batch updates for multiple items or do more
   advanced customizations (e.g. expanding a mediaId representing
   a playlist to multiple items).

Both issues can be solved by passing in a list of items and
returning a ListenableFuture. The callback itself can also move
into MediaSession.Callback for consistency with the other
callbacks.

PiperOrigin-RevId: 451857319
2022-05-30 16:48:41 +00:00
tonihei
342be88d81 Improve playlist operation behavior of session test MockPlayer
The MockPlayer currently:
 - uses separate fields for single mediaItem vs multiple mediaItems
 - replaces all items on addMediaItem operations
 - does nothing on remove/move operations.

Fix all of this by using a single field that replicates the player
operations directly.

Some tests also need to be updated to make them more realistic
(for example only removing items from a playlist that have
previously been added).

PiperOrigin-RevId: 451857271
2022-05-30 16:47:44 +00:00
rohks
001090cc43 Migrate leaf listeners of Player to new onCues override
PiperOrigin-RevId: 449587030
2022-05-24 11:02:03 +01:00
ibaker
cd142872bb Rename MediaSession.Builder.setSessionCallback to setCallback
Follow-up to c78c1f5891

PiperOrigin-RevId: 449492810
2022-05-24 10:59:06 +01:00
ibaker
c78c1f5891 Rename nested session callback interfaces to just Callback
This is consistent with other nested callback/listener interfaces like
`Player.Listener`.

PiperOrigin-RevId: 449476261
2022-05-24 10:57:02 +01:00
ibaker
7c235d2b84 Remove all null-tolerant methods from BundleableUtil.
In most cases it's clearer to in-line these null-checks with ternary
operators.

PiperOrigin-RevId: 449474621
2022-05-24 10:56:01 +01:00
rohks
c728647290 Create new class to store cues and timestamp.
We need to pass timestamp for the list of cues so we are defining a new class CueGroup which will store both cues and timestamp.

PiperOrigin-RevId: 449212054
2022-05-24 10:49:48 +01:00
bachinger
1d89c35f7b Add MediaSession.setCustomLayout(List<CommandButton>)
This provides a way for apps to send a custom layout to media3
controllers and legacy controllers by making sure to include custom
actions in the legacy playback state when built in the PlayerWrapper
for broadcasting.

PiperOrigin-RevId: 447967600
2022-05-24 10:30:00 +01:00
bachinger
4c838043d3 Dispatch custom action in MediaSessionLegacyStub
A custom action sent by legacy controllers as for instance the System UI mini player arrive at MediaSessionCompat.Callback.onCustomAction() and need to be dispatched to the session callback as a such.

PiperOrigin-RevId: 447486859
2022-05-10 17:50:30 +01:00
christosts
7a631f4050 MediaSessionService: define foregroundServiceType
PiperOrigin-RevId: 447467287
2022-05-10 17:49:22 +01:00
ibaker
931bc70d5f Migrate usages of the deprecated TrackSelectionParameters.CREATOR
PiperOrigin-RevId: 446400192
2022-05-09 10:52:11 +01:00
ibaker
1b2e9da0af Rename CONTENT_TYPE_ @AudioContentType values to AUDIO_CONTENT_TYPE_*
This is consistent with the IntDef name, and frees up the CONTENT_TYPE_
prefix for the @ContentType values (which are currently just TYPE_*,
and therefore ambiguous with lots of other 'type' values in C).

PiperOrigin-RevId: 445356476
2022-05-09 10:34:27 +01:00
bachinger
6708b43bfb Fix incorrect format variable
PiperOrigin-RevId: 444530943
2022-04-26 13:30:27 +01:00
Ian Baker
85c09753ef Merge pull request #59 from h6ah4i:fix/cleanup-callbacks-on-media-controller-release
PiperOrigin-RevId: 441253378
2022-04-26 14:32:15 +01:00
olly
83daa052cb Rename TracksInfo and TrackGroupInfo
1. TracksInfo is renamed to Tracks
2. TracksInfo.TrackGroupInfo is renamed to Tracks.Group

PiperOrigin-RevId: 441232373
2022-04-26 14:30:14 +01:00
bachinger
3ac7e0e84e Update error state of legacy playback state if authentication fails
This change adds the ability to update the error code of the PlaybackStateCompat in
cases we need this for backwards compatibility. It is applied in the least
intrusive way because normally, return values of a service method should not change
the state of the `PlaybackStateCompat`, just because it has nothing to do with the
playback state but rather with the state of the `MediaLibrarySession`.

For this reason only the error code `RESULT_ERROR_SESSION_AUTHENTICATION_EXPIRED`
is taken into account while all other error codes are not mapped to the
`PlaybackStateCompat'.

PiperOrigin-RevId: 438038852
2022-04-06 11:25:27 +01:00
Haruki Hasegawa
db1a1dc40c
Add more test cases for checking the MediaController#release() behavior
Current implementation of the release() method have a bug;
it does not clear pending messages/callbacks queued to the
applicationHandler.
2022-03-27 00:13:01 +09:00
christosts
4456a865cc Misc cleanup in session tests
PiperOrigin-RevId: 432430345
(cherry picked from commit 8e98187a1e08167cbef08c94e632c8d84a4667f1)
2022-03-08 16:58:05 +00:00
christosts
25004f8988 Remove CountDownLatch from MockPlayer
The MockPlayer has a single CountDownLatch field and multiple boolean
flags that track if a player method was called. Upon calling the methods
the latch count. Tests set the latch count to match exactly with the
number of expected player interactions then block the test thread until
the latch reaches zero and assert the respective method flags are true.

This is subject to false positives. If the underneath implementation
changes and call more player method, then the test thread will unblock
as soon as a certain number of interactions is performed, which may be
less than what the test expected originally. However, the test may stil
pass if the player thread had enough time to update the expected method
flag.

This change removes the single CountDownLatch and the boolean flags and
instead it adds APIs to query the MockPlayer if a method has been called
and await until a method is called. Internally, the MockPlayer has a
ConditionVariable per method.

PiperOrigin-RevId: 432399077
(cherry picked from commit 45d512160c7c14eda33785a632a1fc3eebc9769d)
2022-03-08 16:58:05 +00:00
christosts
8e98187a1e Misc cleanup in session tests
PiperOrigin-RevId: 432430345
2022-03-04 14:24:42 +00:00
christosts
45d512160c Remove CountDownLatch from MockPlayer
The MockPlayer has a single CountDownLatch field and multiple boolean
flags that track if a player method was called. Upon calling the methods
the latch count. Tests set the latch count to match exactly with the
number of expected player interactions then block the test thread until
the latch reaches zero and assert the respective method flags are true.

This is subject to false positives. If the underneath implementation
changes and call more player method, then the test thread will unblock
as soon as a certain number of interactions is performed, which may be
less than what the test expected originally. However, the test may stil
pass if the player thread had enough time to update the expected method
flag.

This change removes the single CountDownLatch and the boolean flags and
instead it adds APIs to query the MockPlayer if a method has been called
and await until a method is called. Internally, the MockPlayer has a
ConditionVariable per method.

PiperOrigin-RevId: 432399077
2022-03-07 11:30:00 +00:00
olly
bdc3af1416 Remove deprecated Player track methods
getCurrentTrackGroups and getCurrentTrackSelections are
retained for now, but moved from Player to ExoPlayer, to
ease the transition for some application code that currently
uses these methods.

PiperOrigin-RevId: 430036355
2022-02-22 10:35:04 +00:00
tonihei
ea5245ae2b Fix the position of IntDefs to match TYPE_USE
PiperOrigin-RevId: 427131569
2022-02-21 17:04:12 +00:00
olly
661449d7cd Revert of 87420e5f9bd1671cd3068185f7358f5faba53e71
PiperOrigin-RevId: 426996878
2022-02-21 17:04:12 +00:00
ibaker
c85799cc6c Fix the position of IntDefs to match TYPE_USE
PiperOrigin-RevId: 426855255
2022-02-21 16:56:37 +00:00
tonihei
287182952d Fix the position of IntDefs to match TYPE_USE
#minor-release

PiperOrigin-RevId: 427131569
2022-02-08 11:07:50 +00:00
olly
1f7174e731 Revert of 87420e5f9bd1671cd3068185f7358f5faba53e71
PiperOrigin-RevId: 426996878
2022-02-08 11:07:43 +00:00
ibaker
87420e5f9b Fix the position of IntDefs to match TYPE_USE
#minor-release

PiperOrigin-RevId: 426855255
2022-02-07 10:49:31 +00:00
olly
596d98a048 Shorten logging tag to required length
PiperOrigin-RevId: 424858504
2022-01-28 16:51:06 +00:00
jaewan
cd56084b3e Fix flaky MediaBrowserListenerTest
MediaNotificationHandler tries to connect session in the same
process, so tests should be aware MediaControllers from the
MediaNotificationHandler.

PiperOrigin-RevId: 422330424
2022-01-25 18:34:25 +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
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
olly
f2ad8ccd3c Shorten log tags to 23 char limit
When calling Android's Log class directly, there's a LongLogTag
lint check that detects tags over the 23 char limit, however it
cannot detect long log tags in ExoPlayer due to the way that we
log via our own Log class. This commit adds @Size annotations to
enforce the same rule.

PiperOrigin-RevId: 413976364
2021-12-07 17:37:31 +00:00
olly
c046f40fd0 Fixes for some minor misc issues
- Unnecessary deprecation suppressions
- Dead code
- Broken Javadoc

PiperOrigin-RevId: 409357884
2021-11-19 14:44:25 +00:00
tonihei
313517e092 Use app target sdk of 29 everywhere.
PiperOrigin-RevId: 407807694
2021-11-09 10:10:10 +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
65c2bd981c Add missing LibraryResult type parameters
PiperOrigin-RevId: 407051126
2021-11-09 10:07:30 +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
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
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
Andrew Lewis
933e207b3e Update to androidx.media3
PiperOrigin-RevId: 405656499
2021-10-27 09:12:46 +01:00