72 Commits

Author SHA1 Message Date
christosts
6f8863fc11 Minor naming cleanup in MediaControllerListenerTest
PiperOrigin-RevId: 480041937
2022-10-17 15:45:33 +00:00
christosts
ba1ecafb8f MediaControllerListenerTest: use local MediaController instances
Replace the instance-field MediaController with a local instance created
in each test.

PiperOrigin-RevId: 480039768
2022-10-17 15:43:28 +00:00
bachinger
9e310150a9 Remove unofficial link from test case
PiperOrigin-RevId: 477101201
2022-09-30 18:25:28 +00:00
tonihei
d2887d5237 Remove test that just times out
One of the tests in MediaBrowserListenerTest caused the remote
browser service to crash and then just timed out. As this asserts
nothing useful besides checking that the timeout method is working,
we can remove the test.

Crashing the remote browser service had the side effect of letting
subsequent tests in the same class fail because the previous session
was never released and was still present in the static MediaSession
SESSION_ID_TO_SESSION_MAP instance, which prevented the creation
of new sessions with the same id. This is only an issue in test
runs because a real process would also lose its static variables
when it crashes.

PiperOrigin-RevId: 476905337
2022-09-30 18:22:32 +00:00
christosts
260aabb6e9 MediaControllerListenerTest: add bugs IDs in TODOs
PiperOrigin-RevId: 472974903
2022-09-30 17:43:45 +00:00
bachinger
73f86682e9 Remove assertion that prevents masking of ad periods
The assertion asserts against a `Period` and an `AdPlaybackState` which actually
asserts against a resolved ad which is what `ExoPlayerImplInternal` does later and
what gives us a `SEEK_ADJUSTMENT`. However, this assertion is not required at the
moment of masking, because we are sure that the resolved seek results in a content
period and never an ad period.

#minor-release
Issue: androidx/media#122
PiperOrigin-RevId: 471827072
2022-09-30 17:24:00 +00:00
tonihei
59895646e0 Define CueGroup.EMPTY_TIME_ZERO for convenience
We create an empty CueGroup in many places as default or
where none is needed. Instead, we can define a constant
for this purpose and reuse it.

PiperOrigin-RevId: 467944841
2022-09-30 16:43:22 +00:00
christosts
7a7e1eb23b MediaNotificationManager: handle playback ended
When the player finishes playback and reaches the STATE_ENDED,
the notification remains visible with a pause button and the
service is kept in the foreground. This is a bug.

With this change, when the player reaches the STATE_ENDED, the
service is stopped from the foreground and a notification is shown
with a play button. If the play icon is tapped, the player will restart
playback of the last played item. Playing the last played item again
is the existing behavior when play/pause commands are received from
the legacy MediaSession (e.g. BT headset buttons).

#minor-release

Issue: google/ExoPlayer#112
PiperOrigin-RevId: 467231509
2022-09-30 16:36:20 +00:00
bachinger
a28b3ef778 Add interface version of MediaSessionStub
PiperOrigin-RevId: 464052708
2022-08-08 08:32:29 +00:00
bachinger
c8089ead42 Add interface version of MediaControllerStub
PiperOrigin-RevId: 463930162
2022-08-08 08:25:47 +00:00
tonihei
ac42b593cc Delay unbinding the controller until pending commands are handled.
Once a controller bound to a MediaSessionService unbinds, this service
may be destroyed immediately if this was the last bound controller and
the service isn't started in the foreground.

At the time of releasing the controller, there may still be pending
commands that need to be handled by the session service. These commands
may cause the session service to post a foreground notification to
keep it alive. So to avoid the destruction of the service while these
commands are still handled, we need to keep the controller bound.

We also add a timeout in case the session tasks are never completed
by the session implementation. In case the controller is destroyed,
the unbinding happens automatically by the system.

PiperOrigin-RevId: 463802220
2022-08-08 08:19:35 +00:00
ibaker
2deb435625 Annotate methods that always return this with @CanIgnoreReturnValue
It's always safe to ignore the result of these methods, because the
caller already has a reference to the returned value.

PiperOrigin-RevId: 462388947
2022-08-08 07:55:25 +00:00
tonihei
ee209690cb Ensure pending commands are still sent in MediaController.release()
We currently clear all pending messages, including the one that flushes
pending commands to the MediaSession. To ensure all commands that have
been called before controller.release() are still sent, we can manually
trigger the flush message from the release call.

Related to handling the final flush because disconnecting the controller,
MediaSessionStub didn't post the removal of the controller to the
session thread, creating a race condition between removing the controller
and actually handling the flush.

Issue: androidx/media#99
PiperOrigin-RevId: 462342860
2022-07-21 13:00:20 +00:00
tonihei
7cb7636ed9 Run MediaSessionStub commands in order
Some commands are run asynchronously and subsequent commands need
to wait until the previous one finished. This can be supported
by returning a Future for each command and using the existing
command execution logic to wait for each Future to complete.

As some MediaSessionStub code is now executed delayed to when it
was originally created, we also need to check if the session is
not released before triggering any actions or sending result codes.

Issue: androidx/media#85
PiperOrigin-RevId: 462101136
2022-07-21 12:54:06 +00:00
bachinger
5bf9e2fb31 Exclude tracks if COMMAND_GET_TRACKS is not available
Issue: androidx/media#102
#minor-release
PiperOrigin-RevId: 461891031
2022-07-21 12:50:29 +00:00
bachinger
9a895cd18f Implement getCurrentTracks in MediaController
After this change the current tracks are sent to the controller as part of
`PlayerInfo` and call `Listener.onTracksChanged()` in case of a change in tracks.

PiperOrigin-RevId: 461578695
2022-07-21 12:40:39 +00:00
rohks
74d61bbffb Add timestamp to CueGroup
`TextRenderer` is updated to output `CueGroup`, which contains the presentation time of the cues, in microseconds.

PiperOrigin-RevId: 456531399
2022-06-27 10:38:20 +01:00
bachinger
8f844b32fd Avoid out of bounds when setting less media items than in playlist
Issue: androidx/media#86
#minor-release
PiperOrigin-RevId: 455182232
2022-06-15 18:55:54 +00:00
tonihei
21d4e85817 Remove setMediaUri/onSetMediaUri
This code path is now completely redundant as the same effect can be
achieved by using player.setMediaItem.

#minor-release

PiperOrigin-RevId: 455115567
2022-06-15 15:32:14 +00:00
tonihei
b475f1f2da Support setMediaItem(s) in MediaControllerImplLegacy
These calls were not implemented so far as they require a mix of
initial prepareFrom/playFrom calls and addQueueItem. We can also
support clients without queue handling to set single MediaItems.

To make the calls consistent and predictable in the session,
we need to ensure that none of the play/pause/addQueueItem/
removeQueueItem/prepare/playFromXYZ/prepareFromXYZ are called
before the controller is prepared and has media.

#minor-release

PiperOrigin-RevId: 455110246
2022-06-15 15:30:05 +00:00
tonihei
5333c67d08 Add COMMAND_SET_MEDIA_ITEM to Player.Commands
Some Player implementations have no playlist capability but can still
set a MediaItem for playback. Examples are a MediaController connected
to a legacy MediaSession, ExoPlayer up to 2.12 or MediaPlayer.

To indicate this capability, we need an allowed command in addition
to COMMAND_CHANGE_MEDIA_ITEMS that just allows to set a single item
that replaces everything that is currently played.

#minor-release

PiperOrigin-RevId: 453879626
2022-06-09 17:46:14 +00:00
tonihei
bd126ec5c5 Forward legacy controller onPlay/PrepareFromXY calls to onAddMediaItems
These legacy callbacks are currently forwarded to onSetMediaUri which
will be removed in the future.

Also make sure to only call player.prepare/play after the items have
been set.

The calls to onAddQueueItem are also forwarded to onAddMediaItems to
actually allow a session to resolve these items to playable media, which
wasn't possible so far.

PiperOrigin-RevId: 453625204
2022-06-09 17:40:26 +00:00
christosts
8d326312fb Ignore flaky test
PiperOrigin-RevId: 453168843
2022-06-07 16:28:11 +00:00
christosts
34ca3bc3c3 De-flake test in MediaSessionPermissionTest
This change makes MediaSessionPermissionTest.removeMediaItems()
non-flaky. This is a quick fix though it'd be good to refactor this
test file.

PiperOrigin-RevId: 453162764
2022-06-07 16:27:21 +00:00
ibaker
b8ca5b8951 Add @deprecated javadoc to all @Deprecated @Override methods
This ensures the 'use X instead' message is easily visible in the
generated HTML for the overriding method. Currently it's not, e.g.:
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/BasePlayer.html#getCurrentWindowIndex()

#minor-release

PiperOrigin-RevId: 452002224
2022-05-31 10:44:48 +00:00
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