213 Commits

Author SHA1 Message Date
ibaker
373c23c11b Create NotificationChannel in DefaultMediaNotificationProvider.Api26
The inner class avoids a verification failure, which can lead to slower
execution at runtime.

PiperOrigin-RevId: 483639417
(cherry picked from commit 026aea7d3d85406ef9acf4e65cfffbc5e683a762)
2022-10-25 11:54:05 +00:00
microkatz
9fbc464ce3 Merge pull request #141 from tzugen:patch-4
PiperOrigin-RevId: 483395026
(cherry picked from commit e2a77f7be9989aaf70749f7caf62bc8b3f1feb0b)
2022-10-31 11:28:21 +00:00
bachinger
adf264c7c0 Minor simplification when setting metadata to platform session
PiperOrigin-RevId: 482805730
(cherry picked from commit a47f530b926394f6e1f3c11bbcbb2d2e38434e5a)
2022-10-21 15:56:34 +00:00
tianyifeng
1ce13aa721 Add CacheBitmapLoader in the session module
* Add `CacheBitmapLoader`.
* Add `CacheBitmapLoaderTest`.
* Remove the `BitmapLoadRequest` and some bitmap caching logic in `DefaultMediaNotificationProvider` since we moved all of them in `CacheBitmapLoader`.
* Modify `DefaultMediaNotificationProviderTest`.

PiperOrigin-RevId: 482787445
(cherry picked from commit ca4edff1fd61c58ce5c56f9bbd9ff80ce8a6670c)
2022-10-21 14:28:35 +00:00
christosts
0727b1f6f2 Use Service.stopForeground(int) on API 24+
The MediaNotficationManager stops the service from the foreground
calling Service.stopForeground(boolean) which is deprecated in API 33.
This change calls Service.stopForeground(int), which was added in API
24.

#minor-release

PiperOrigin-RevId: 482190332
(cherry picked from commit 601eaba7a6dcce963d5a3547d939ea41404ad3fe)
2022-10-19 13:41: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
christosts
0ceec3ebb9 MediaControllerImplBase: clean imports
Remove static imports to constants and imports to intdefs, to make the
code more readable.

PiperOrigin-RevId: 479594144
(cherry picked from commit 36e12fbadb7b274f770a5904675493300c8fa89c)
2022-10-07 16:07:50 +00:00
aquilescanta
506653bbcc Fix typo in MediaController javadoc
PiperOrigin-RevId: 479268879
(cherry picked from commit 0beccb6e141f40d6cb8cca4839213df2ab600c01)
2022-10-06 10:21:12 +00:00
christosts
1cfeddc369 Misc fix on DefaultMediaNotificationProviderTest
PiperOrigin-RevId: 479079184
(cherry picked from commit bf948db669c32ab5eea2432b7c2c61667af1388a)
2022-10-05 17:22:40 +00:00
Googler
9842c273e9 Allow using different notification IDs for different media sessions
When a media service currently produces multiple media sessions, the notification of the second session overwrites the notification of the first one, because all sessions use the same notification ID. When we use different notification IDs for different sessions, multiple media notifications can be up at the same time, which means that they can both be controlled at the same time.

PiperOrigin-RevId: 478709069
(cherry picked from commit 7783c6e4f71943b543ddb569b120bdbbab362b96)
2022-10-04 07:38:38 +00:00
bachinger
05ebdb9211 Don't start the service in the foreground with a pause intent
`PlaybackStateCompat.toKeyCode(command)` was replaced by our
own implementation of `toKeyCode()`. The legacy implementation used PLAY and PAUSE, while the new implementation uses PLAY_PAUSE. This made `pause` a pending intent that attempt to start the service in the foreground, but `service.startForeground()` won't be called in `MediaNotificationManager.updateNotificationInternal` when paused.

PiperOrigin-RevId: 476895752
(cherry picked from commit acd9e581c494b18f6347f5abb2cf9fc82344c723)
2022-09-26 14:56:00 +00:00
bachinger
cc6c6aa62b Call callback future listeners on app handler
Calling maybeUpdateLegacyErrorState potentially creates a new legacy playback
state which involves calling player methods. This change makes sure that the call
sites of `maybeUpdateLegacyErrorState` are called on the app thread as enforced by
the library.

PiperOrigin-RevId: 476406282
(cherry picked from commit 74124f48ea838fcdb436726ba8337e82abc7552e)
2022-09-23 17:34:25 +00:00
rohks
4d43f840f1 Fix instrumentation tests not working via Gradle
PiperOrigin-RevId: 475560401
(cherry picked from commit c96e010d351bdd8b45f88b9731c5a80bcec0d2d4)
2022-09-20 15:25:38 +00:00
Googler
8773b59fb5 Clarify exception message.
The exception fires when intent resolution fails to find a service which declares an appropriate intent-filter. The existing message is confusing; it's trying to say that the service couldn't be found but the double negative renders it incorrect.

#cleanup
#minor-release

PiperOrigin-RevId: 472736740
(cherry picked from commit 15d3d74e16bf9830e5ae32d0a8edf691474d0b4e)
2022-09-07 15:56:07 +00:00
Googler
1bf431566f Fix 4 ErrorProneStyle findings:
* Non-standard parameter comment; prefer `/* paramName= */ arg`
  (see http://go/bugpattern/ParameterComment) (2 times)
* This catch block catches an exception and re-throws another, but swallows the caught exception rather than setting it as a cause. This can make debugging harder.
  (see http://go/bugpattern/UnusedException)
* This comment contains Javadoc or HTML tags, but isn't started with a double asterisk (/**); is it meant to be Javadoc?
  (see http://go/bugpattern/AlmostJavadoc)

This CL looks good? Just LGTM and Approve it!
This CL doesn’t look good? This is what you can do:
* Revert this CL, by replying "REVERT: <provide reason>"
* File a bug under go/error-prone-bug for category ErrorProneStyle if there's an issue with the CL content.
* File a bug under go/rosie-bug if there's an issue with how the CL was managed.
* Revert this CL and not get a CL that cleans up these paths in the future by
replying "BLOCKLIST: <provide reason>". This is not reversible! We recommend to
opt out the respective paths in your CL Robot configuration instead:
go/clrobot-opt-out.

This CL was generated by CL Robot - a tool that cleans up code findings
(go/clrobot). The affected code paths have been enabled for CL Robot in //depot/google3/java/com/google/android/libraries/media/METADATA which is reachable following include_presubmits from //depot/google3/third_party/java_src/android_libs/media/METADATA.
Anything wrong with the signup? File a bug at go/clrobot-bug.

#codehealth

Tested:
    Local presubmit tests passed.
PiperOrigin-RevId: 472255768
(cherry picked from commit 3a2e0d37177034b3012204ac16cf7b3d4e3436b9)
2022-09-05 12:19:14 +00:00
bachinger
1b7060776b 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
(cherry picked from commit 73f86682e94024c780564dbc287f06d47dfeca26)
2022-09-02 17:05:21 +00:00
rohks
422e317156 Provide methods to override notification fields
`contentTitle` and `contentText` can now be overridden.

Issue: androidx/media#150
PiperOrigin-RevId: 471287701
(cherry picked from commit a45df2fdcb5c0d1e8c6eb8ab23e421e8d9233e68)
2022-08-31 17:23:20 +00:00
rohks
4c29eee330 Switch incorrectly configured native multidex to legacy
Native multidex can only be used for binaries with minSdkVersion of 21 or higher, but minSdkVersion was specified to 16.

PiperOrigin-RevId: 470003836
(cherry picked from commit 5b3f32023063c90a63a5e30eeefab161b0a7f824)
2022-08-25 16:07:42 +00:00
Marc Baechinger
f73018a269 Merge pull request #157 from vanniktech:onAddMediaItems-example
PiperOrigin-RevId: 469410221
(cherry picked from commit ca41026c5b4d03815e83c85987efceee5fe2e144)
2022-09-30 16:56:19 +00:00
rohks
e7aee55fca Fix missing commas in documentation of DefaultMediaNotificationProvider
PiperOrigin-RevId: 468257769
(cherry picked from commit 6950f3aaa8bf229c0441b3d10cae75bef3ee30f5)
2022-08-17 18:54:01 +00:00
tonihei
f3d48c21f4 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
(cherry picked from commit 59895646e03ee15aed5e80fb8e60b7f98a7afe5f)
2022-08-16 16:27:56 +00:00
christosts
19cc87c04f 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
(cherry picked from commit 7a7e1eb23b4bbf7d0c6c15b2f484434e65cd2c68)
2022-08-12 16:53:36 +00:00
bachinger
1bee4f86fb Add interface version of MediaSessionStub
PiperOrigin-RevId: 464052708
(cherry picked from commit a28b3ef77843bb75938b2ca738ebedf0c29c1129)
2022-07-29 11:52:06 +00:00
tonihei
7411a31e7b Merge pull request #109 from tzugen:patch-1
PiperOrigin-RevId: 464045351
(cherry picked from commit 61e4f92310091737b7107662d52ef8e13319f6e5)
2022-08-08 08:28:35 +00:00
bachinger
8c560d2115 Add interface version of MediaControllerStub
PiperOrigin-RevId: 463930162
(cherry picked from commit c8089ead42d940c550955f7786447ad87784b9df)
2022-07-28 21:45:49 +00:00
christosts
60b334cd01 Minor: Change URL in test
Use a URL with a `.test` tld (RFC 2606) to make it clear
it's an testing URL.

PiperOrigin-RevId: 463852174
(cherry picked from commit 4713c7fea835a8b73b41f6e4723f141828814e44)
2022-07-28 16:12:28 +00:00
tonihei
561b83e282 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
(cherry picked from commit ac42b593cc3280b866d42cdc11d57bb031b39757)
2022-07-28 11:10:36 +00:00
bachinger
38a133b23a Clean up hashCode/equals of SessionTokenImplBase
#minor-release

PiperOrigin-RevId: 463338680
(cherry picked from commit 2bde3f1e31f2d74cb75213eb07811fced38e9072)
2022-07-26 15:10:46 +00:00
bachinger
5a4e244d94 Normalize constructors of SessionTokenImplBase/SessionTokenImplLegacy
#minor-release

PiperOrigin-RevId: 463328436
(cherry picked from commit 428fc896355828e11bf352c9b2c70abf2f13dc2d)
2022-07-26 14:12:19 +00:00
christosts
faf1f35feb DefaultMediaNotificationProvider: limit requests to load same bitmap
The DefaultMediaNotificationProvider caches the last loaded artwork
bitmap so that the bitmap isn't loaded again when the notification is
updated, e.g., the player is transiting from playing to paused. However,
loading bitmap requests for bitmaps that are already being loaded are
not suppressed. For example, if the notification is updated while the
artwork is still downloading, the same artwork might be downloaded
multiple times.

This change suppresses a bitmap load request if the same artwork is
still being loaded, to avoid additional artwork downloads.

#minor-release

PiperOrigin-RevId: 462572221
(cherry picked from commit dd2c16bc459af50c126b9666d3134595ba58e4cb)
2022-07-22 09:05:10 +00:00
ibaker
878279425b 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
(cherry picked from commit 2deb435625c7569cb0bd250848adaa846884dc50)
2022-07-21 15:24:07 +00:00
tonihei
29246fb1b2 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
(cherry picked from commit ee209690cb54fc800cf3a213f5075c9aaf51463c)
2022-07-21 10:10:22 +00:00
ibaker
0667c74dc5 Slightly disentangle MediaBrowser/Controller(Impl)Base/Legacy
These constructors are currently very intertwined, passing `this`
references from the constructor of one to the constructor of another
before the first constructor is complete (and so the `this` reference
isn't really valid yet).

This change uses checker framework `@UnderInitialization` and
`@NotOnlyInitialized` annotations to make it more clear that the
references are not available yet. For the one 'direct' access needed
in the second constructor (calling `getApplicationLooper()`) we now
pass the `applicationLooper` directly alongside (to avoid needing to
dereference the reference 'too early').

This change also ensures that where a class hierarchy has a
'dependent' class hierarchy, the 'subclass' instance is always used
(by both subclass and superclass) without casting or manually hiding
the superclass field, by defining an overridable `getFoo()` method
instead and always using it.

#minor-release

PiperOrigin-RevId: 462335043
(cherry picked from commit 287c757944720c6804e8f1cc074e28134f7da528)
2022-07-21 09:20:33 +00:00
tonihei
33c5aa7a88 Rename seq to sequenceNumber in MediaSessionStub
"seq" is not a well-defined abbreviation and the value is
also an integer, so sequenceNumber is better than just sequence.

PiperOrigin-RevId: 462129581
(cherry picked from commit 4a4a74edffe39fbb745513a42235a523da7bb185)
2022-07-20 13:47:47 +00:00
christosts
62a2d76d00 Make DefaultMediaNotificationProvider more configurable
Add a Builder to constructor DefaultMediaNotificationProvider. The
Builder can also set the provider's:
- notification ID
- notification channel ID
- notification channel name

The change adds an API for apps to set the small icon in notifications.

#minor-release
Issue: androidx/media#104
PiperOrigin-RevId: 462111536
(cherry picked from commit 436ff6d86a4b8de5324d3b3b08bb655b75ca6632)
2022-07-20 11:41:30 +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
tonihei
d84662e5ce Properly chain commands in MediaSessionStub
The commands currently use a task and a postTask that are chained
together manually. In some cases, e.g. when adding MediaItems,
the postTask is already a chain of commands in itself.

To allow using the entire command handling as a single task
(for simplified queueing), we can change the implementation to
always create a single task. If multiple subtasks need to be
chained together, we can do that by wrapping the method calls.
In case a task is asynchronous, we can also use Futures to
chain them together.

Overall, this is just a refactoring and changes no logic.

Issue: androidx/media#85
PiperOrigin-RevId: 462085724
(cherry picked from commit 45f1f5b37858ce937164be568a598dbb84bf654b)
2022-07-20 08:56:08 +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
c37c6812d6 Remove unused argument
PiperOrigin-RevId: 461830378
(cherry picked from commit e8b5aad3d703ef99b0d03957f16c704b05b7883c)
2022-07-19 09:16:55 +00:00
tonihei
481205a88f Use Futures for MediaSession command queue instead of Runnables
Some commands may be asynchronous and subsequent commands need to
wait for them to complete before running. This change updates the
queue to use (and listen to) Futures instead of calling Runnables
directly. The commands are currently still added as Runanbles
though, so this change is a no-op.

Also moves the permission check in MediaSessionImpl to before
queueing the command because the permission should be check at
the time of calling the method.

When executing the comamnds in the queue, we need to be careful
to avoid recursion in the same thread (which happens when both
the Future is immediate and running on the correct thread already).
To avoid recursion, we detect this case and loop the commands
instead.

Issue: androidx/media#85
PiperOrigin-RevId: 461827264
(cherry picked from commit dee80788e4fc5e82739ae014a5d2759b77f03daa)
2022-07-19 08:59:30 +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
olly
6eb30ce233 Add TODOs for registerReceiver calls without flag
PiperOrigin-RevId: 461165173
(cherry picked from commit 9271572e950230a24da69a6ec5838dd838ea672d)
2022-07-15 10:34:53 +00:00
rohks
49f4c9342d Add timestamp to CueGroup
`TextRenderer` is updated to output `CueGroup`, which contains the presentation time of the cues, in microseconds.

PiperOrigin-RevId: 456531399
(cherry picked from commit 74d61bbffb834cdb50d003a8de66af0e094ef702)
2022-06-22 17:19:55 +01:00
bachinger
87b817b0f9 Fix incorrect link tags
PiperOrigin-RevId: 459215618
(cherry picked from commit 87adb88f57afb050a96a9c67dd9eb55fb3a6706c)
2022-07-06 11:02:12 +00:00
bachinger
3de3f41757 Document custom commands in the DefaultMediaNotificationProvider
Issue: androidx/media#103
#minor-release
PiperOrigin-RevId: 458465479
(cherry picked from commit 2c0806814bd28612834b51b8489a138e5eb10ecf)
2022-07-01 14:27:24 +00:00
bachinger
14aced6304 Avoid out of bounds when setting less media items than in playlist
Issue: androidx/media#86
#minor-release
PiperOrigin-RevId: 455182232
(cherry picked from commit 8f844b32fdf4d41d6a5690e57e55d0c383ee7e3e)
2022-06-15 19:05:26 +00:00
bachinger
5ebc07ce76 Updating translations
#minor-release

PiperOrigin-RevId: 455128997
(cherry picked from commit 958105c91c931fa942ce7de4e8311589eca76564)
2022-06-15 17:00:36 +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
tonihei
6ed3e40681 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
(cherry picked from commit b475f1f2daba8e0ed2497cbf17f4b834e58c59a4)
2022-06-15 16:52:51 +00:00