22 Commits

Author SHA1 Message Date
tonihei
93605303ad Update available commands when setting a new player in MediaSession
PiperOrigin-RevId: 523633865
(cherry picked from commit ae875648a72b08f24c1e41cc5822fc24265dfd9b)
2023-04-18 15:00:09 +01:00
bachinger
5528baaad9 Do not assume a valid queue in 3rd party sessions
This change fixes an issue that can be reproduced when
a controller `onConnect` creates a `QueueTimeline` out
of the state of a legacy session and then `prepare` is called.

`activeQueueItemId`, `metadata` and the `queue` of the legacy
session are used when a `QueueTimeline` is created. The change
adds unit tests to cover the different combinatoric cases these
properties being set or unset.

PiperOrigin-RevId: 505731288
(cherry picked from commit 4a9cf7d069b1b35be807886d59d87c396b19876c)
2023-02-02 13:22:38 +00:00
tonihei
c357e67dd1 Filter available commands based on PlaybackStateCompat actions
This allows a MediaController to understand which methods calls
are available on a legacy session.

PiperOrigin-RevId: 504306806
(cherry picked from commit 067340cb0a03dede0f51425de00643fe3789baf2)
2023-01-26 14:26:00 +00:00
bachinger
5d84804070 Use onMediaMetadataChanged for updating the legacy session
Issue: androidx/media#219
PiperOrigin-RevId: 501080612
(cherry picked from commit 375299bf364041ccef17b81020a13af7db997433)
2023-01-25 18:18:41 +00:00
bachinger
782a69e38c Migrate BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS to Media3
PiperOrigin-RevId: 490376734
(cherry picked from commit 1803d1cdb8cf429c3d0a3fdbbecbad25145db8c4)
2023-01-25 17:38:34 +00:00
tonihei
58d670d941 Align PlaybackStateCompat states with logic in MediaSessionConnector
Creating the PlaybackStateCompat from a media3 Player state is done
already by the MediaSessionConnector (and used widely). The media3
session module should set the same states under the same circumstances
to ensure compatiblity and consistency.

PlaybackStateCompat changes made in media3 session:
 - Use STATE_STOPPED when player is ended instead of STATE_PAUSED
 - Use STATE_PLAYING when playback is suppressed temporarily.
 - Set the playback speed to 0 if the player is not playing.
 - Add extras for mediaId and user-set playback speed.

Part of the problem was that Player.isPlaying() was used to check
the state. Unfortunately, MockPlayer.isPlaying() is implemented in
a way that makes it hard to test these changes, because the value
is set independently of playbackState, playWhenReady and suppression
reason. To be able to write consistent, logical tests, this change
also removes the independent setting of isPlaying in MockPlayer to
align it better with a real player. This requires to update some
other tests to use alternative methods.

PiperOrigin-RevId: 487500859
(cherry picked from commit c5e071e556931331cc780fda5177d556d51ff3da)
2022-11-10 12:40:37 +00:00
tianyifeng
f5afec955a Load bitmaps for MediaMetadataCompat and handle the metadata updates.
* Add `Listener` in `MediaSession` with method `onNotificationRefreshRequired(MediaSession)`.
* Add `MediaSessionService` as the listener of the `MediaSession` when `MediaSession` is added to `MediaSessionService`
* Load bitmap when update metadata in `MediaSessionLegacyStub` and call `onNotificationRefreshRequired` when bitmap asynchronously arrives.

PiperOrigin-RevId: 485376145
(cherry picked from commit 77fedd8d7d511ff97b0441aa9136d0f1aaecef4b)
2022-11-01 18:43:26 +00:00
christosts
ba84c2a09c MediaController: Add missing event flags (1/2)
This is the first commit out of two. This change adds the missing event
flags for the onEvents() callback when MediaController is connected to a
media3 session (see MediaControllerImplBase). I updated the
MediaControllerListenerTest and MediaControllerStateMaskingTest with
assertions that on onEvents() is called alongside individual
Player.Listener callbacks.

There will be a follow-up change for the case where a MediaController is
connected to a legacy MediaSession (MediaControllerImplLegacy). I've
split this in two separate changes to make the size of the commit
manageable for reviewing.

#minor-release

PiperOrigin-RevId: 481933437
(cherry picked from commit 46d5a0e33bd562cd9e6420b342a68bf112847f83)
2022-10-18 15:54:54 +00:00
bachinger
fc1089f68a Migrate media constants from androidx.media.util.MediaConstants
Adds root extras and metadata extras to MockMediaLibraryService and MockMediaBrowserCompatService and completed test cases for asserting
interoperability with a media1 or Media3 browser.

PiperOrigin-RevId: 480854842
(cherry picked from commit 006a519a0e83d5b9e4262a5bbc228c02b3c9cf5f)
2022-10-13 11:18:46 +00:00
tonihei
c91cdb49e0 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
(cherry picked from commit d2887d523773de75ed99403c22d634538f6c81df)
2022-09-26 15:39:47 +00:00
tonihei
eb823a9ab7 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
(cherry picked from commit 7cb7636ed954f0737aaac2f9cf556715a2ee9b37)
2022-07-20 10:34:22 +00:00
bachinger
a1fc19d3c5 Exclude tracks if COMMAND_GET_TRACKS is not available
Issue: androidx/media#102
#minor-release
PiperOrigin-RevId: 461891031
(cherry picked from commit 5bf9e2fb31d9cc1dea5152e63f738b8d03fcacb3)
2022-07-19 15:39:27 +00:00
bachinger
24bfe3a5e0 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
(cherry picked from commit 9a895cd18f020a4f9df24c142406e91507a76605)
2022-07-18 10:47:57 +00:00
tonihei
6791532778 Remove setMediaUri/onSetMediaUri
This code path is now completely redundant as the same effect can be
achieved by using player.setMediaItem.

PiperOrigin-RevId: 455115567
(cherry picked from commit 21d4e8581701e12743626f49823a667d9f05ed68)
2022-06-15 17:00:27 +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
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
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
Ian Baker
38717ce969 Reformat some javadoc 2022-02-18 14:54:02 +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
ibaker
f37e980018 Migrate media3.session references from Window to MediaItem
#minor-release

PiperOrigin-RevId: 405927299
2021-11-08 15:13:41 +00:00
Andrew Lewis
933e207b3e Update to androidx.media3
PiperOrigin-RevId: 405656499
2021-10-27 09:12:46 +01:00