70 Commits

Author SHA1 Message Date
tonihei
6ac60c6dff Disable enhanced Java 8 desugaring
This avoids that apps have to depend on this additional config

Issue: androidx/media#1312
PiperOrigin-RevId: 631447767
2024-05-07 09:26:36 -07:00
tonihei
16df05ec29 Upgrade Gradle and AGP
The newer versions include a bugfix that automatically highlights
when our project requires enhanced Java 8 desugaring.

Issue: androidx/media#1312
PiperOrigin-RevId: 631373018
2024-05-07 04:20:55 -07:00
bachinger
4777d62d31 Rollback of 8e2869278c
PiperOrigin-RevId: 607264513
2024-02-15 02:35:12 -08:00
asinclair
8e2869278c Internal Cleanup
PiperOrigin-RevId: 607117264
2024-02-14 15:06:10 -08:00
Googler
718cf1299b Fix Kotlin 2.0 compilation error in session demo app
Since Kotlin 2.0 the compiler became better at detecting incorrect
annotation applications. The @OptIn annotation can't be applied to an
expression, so when compiling with Kotlin 2.0 it results in an error.

PiperOrigin-RevId: 604596657
2024-02-06 03:47:20 -08:00
bachinger
b11c0c19b0 Declare demo service as MediaLibraryService
The `PlaybackService` of the demo app is declared
as `androidx.media3.session.MediaSessionService` instead
of `androidx.media3.session.MediaLibraryService`. While
this technically works, its confusing to do that in the
demo app.

Generally, apps that declare the legacy
`android.media.browse.MediaBrowserService` should also
declare `androidx.media3.session.MediaLibraryService`
and the demo app should reflect this common case.

Issue: androidx/media#672
PiperOrigin-RevId: 595320994
2024-01-03 00:51:17 -08:00
tonihei
00425dbe80 Expand MediaItems in session demo instead of just replacing them
When MediaItems are added from the controller, we currently completely
replace the item with the one from our database, overriding any
potential additional information the controller may have set.

Also forward the onAddMediaItems/onSetMediaItems callbacks to common
helper methods instead of redirecting them through super methods

#minor-release
Issue: androidx/media#706
PiperOrigin-RevId: 573799351
2023-10-16 07:05:28 -07:00
ibaker
c7a091a973 Request notification permission when starting session demo app
#minor-release

PiperOrigin-RevId: 572556101
2023-10-11 06:27:59 -07:00
tonihei
fe7c62afe0 Add missing Future cancellation checks
Future.isDone and getDone doesn't imply the Future was successful
and it may have been cancelled or failed.

In case where we handle failure, we should also handle cancellation
to avoid CancellationException to bubble up unchecked.

In demo app code where we use isDone for field initialization, we
want to crash in the failure case (usually security exception where
the connection is disallowed), but we want to gracefully handle
cancellation. Cancellation of these variables usually happens in
Activity.onDestroy/onStop, but methods may be called after this point.

#minor-release

PiperOrigin-RevId: 572178018
2023-10-10 02:14:24 -07:00
tonihei
fd81c904e1 Use more targeted listening in session PlayerActivity
The current metadata updates are triggered by item transitions,
but depending on the speed of loading the playlist, the first
metadata may only be known later via metadata-change callbacks.

Slow playlist loading also means the UI stays empty and it's
beneficial to show a placeholder to avoid the impressions the
UI hangs.

Finally, clean-up by removing unused string constants and merging
all listeners into onEvents

#minor-release

PiperOrigin-RevId: 571951529
2023-10-09 09:01:14 -07:00
bachinger
78f403aa7b Add MEDIA_PLAY_FROM_SEARCH to manifest of session demo app
This is required to make GMS send voice commands to the app.

#minor-release

PiperOrigin-RevId: 571326122
2023-10-06 06:59:19 -07:00
bachinger
52d9fbff73 Update playlist UI when playlist is updated
When changing the playlist on Android Auto the UI of the
activity needs to be kept in sync.

PiperOrigin-RevId: 569528785
2023-09-29 10:42:58 -07:00
bachinger
cbd23925d5 Add demos/session-automotive module
This change also enables Android Auto support for the
session demo.

PiperOrigin-RevId: 569448376
2023-09-29 04:00:58 -07:00
bachinger
2debf0187a Split demo service into its own module for reuse
To support Automotive with the session demo, we need a separate app module.
To do this we need to split the service into its own module and make it
usable from different modules.

PiperOrigin-RevId: 568975271
2023-09-27 15:21:23 -07:00
bachinger
99086b4007 Add default implementation of Callback.onSubscribe
The library already maintains the subscribed controllers internally. This
change adds `MediaLibrarySession.getSubscribedControllers(mediaId)` to
access subscribed controllers for a given media ID.

To accept a subscription, `MediaLibraryService.Callback.onSubscribe` is
required to return `RESULT_SUCCESS`. So far, this isn't the case for the
default implementation of the library.

This change implements `Callback.onSubscribe` to conditionally
provide `RESULT_SUCCESS`. The default calls `Callback.onGetItem(mediaId)` to
assess the availability of the media item. If the app retruns `RESULT_SUCCESS`
with a browsable item, the subscription is accepted. If receiving a valid item
fails, the subscription is rejected.

Issue: androidx/media#561
PiperOrigin-RevId: 568925079
2023-09-27 12:19:34 -07:00
bachinger
742410d517 Use proxy controller to maintain platform session and notification
With this change, the notification controller that is connected by
`MediaNotificationManager`, is used as a proxy controller of the
System UI controller. An app can use the proxy at connection time
and during the lifetime of the session for configuration of the
platform session and the media notification on all API levels.

This includes using custom layout and available player and session
commands of the proxy to maintain the platform session (actions,
custom actions, session extras) and the `MediaNotification.Provider`.

The legacy System UI controller is hidden from the public API,
instead the app interacts with the Media3 proxy:

- System UI is hidden from `MediaSession.getConnectedControllers()`.
- Calls from System UI to methods of `MediaSession.Callback`/
  `MediaLibrarySession.Callback` are mapped to the `ControllerInfo`
  of the proxy controller.
- When `getControllerForCurrentRequest()` is called during an operation of
  System UI the proxy `ControllerInfo` is returned.

PiperOrigin-RevId: 567606117
2023-09-22 06:36:22 -07:00
tonihei
25cd13b3a2 Remove unused values
PiperOrigin-RevId: 559357691
2023-08-24 09:20:33 +01:00
ibaker
a48b99214e Enable @UnstableApi lint in session demo app and add needed @OptIn
PiperOrigin-RevId: 556779020
2023-08-14 17:19:58 +01:00
tonihei
2d3f464008 Update demo app target SDKs to 34
This helps to highlight and document new requirements for apps,
e.g. to add the FOREGROUND_SERVICE_MEDIA_PLAYBACK permission for
background playback.

Issue: google/ExoPlayer#11239
PiperOrigin-RevId: 548666056
2023-07-20 10:11:18 +01:00
bachinger
ea21d27a69 Add custom layout to the state of the MediaController
This change also marks the buttons of the custom layout as
enabled/disabled according to available commands in the controller.
Accordingly, `CommandButton.Builder.setEnabled(boolean)` is deprecated
because the value is overridden by the library.

Issue: androidx/media#38

#minor-release

PiperOrigin-RevId: 547272588
2023-07-13 15:47:50 +01:00
Tofunmi Adigun-Hameed
9aa519f1ee Merge pull request #371 from tatsuyafujisaki:simplify-loadJSONFromAsset
PiperOrigin-RevId: 538423581
2023-06-08 12:34:08 +00:00
Tatsuya Fujisaki
4c54a12af2 Simplify loadJSONFromAsset() 2023-06-06 16:12:01 +00:00
bachinger
230921e4ab Use artwork display mode in demo app
- Use artwork display mode `fill` to improve visual apperance
- Some minor cleanup

#minor-release

PiperOrigin-RevId: 534366246
2023-05-24 15:52:15 +01:00
bachinger
46fb454b3f Add artwork display mode to PlayerView
This change deprecates `PlayerView.setUseArtwork(boolean)` and
introduces `setArtworkDisplayMode(mode)` and
`artworkDisplayMode="off|fit|fill"` instead.

- off: no artwork is displayed (like deprecated useArtwork=false)
- fit: letterbox like media (like deprecated useArtwork=true)
- fill: scales the artwork to fill the entire width/weight of the player view

#minor-release

PiperOrigin-RevId: 534167226
2023-05-24 15:47:03 +01:00
bachinger
96a4ae7e40 Minor session demo app improvements
Basically this change removes a bug that makes video playback stuck when
a video is playing and the user taps the UMO notification to get to
the player activity.

- Use `launchMode="singleTop"` for `PlayerActivity`
- Change session activity to a back stacked activity on service `onDestroy`.

Using a back stacked activity `onDestroy()` will be useful once this demo
app implements playback resumption.

The rest of the changes are aesthetic:

- clean up and optimize screen space usage in UI of `PlayerActivity`
- changed some colors, paddings and spacings
- adds a default artwork for the `PlayerView`

PiperOrigin-RevId: 534152052
2023-05-24 15:45:54 +01:00
ibaker
b3db85133a Add android.namespace to all build.gradle files
This is a pre-requisite for the Android Studio upgrade assistant to
upgrade from AGP 7.2.2 to 8.0.1, otherwise it fails and complains
this is missing.

Issue: androidx/media#409
PiperOrigin-RevId: 533463246
2023-05-19 17:19:15 +01:00
tonihei
804b57ea7b Add LeakCanary to session demo app debug builds
This helps to detect accidental service/activity leaks.

PiperOrigin-RevId: 529391523
2023-05-05 16:41:33 +00:00
ibaker
0f398d511d Temporarily suppress missing permission lint in session demo
#minor-release

PiperOrigin-RevId: 529370535
2023-05-04 13:05:49 +00:00
ibaker
09b474a519 Use a for-each loop instead of forEach in PlaybackService.kt
The current code flags a lint error:

```
Error: Call requires API level 24 (current min is 16): java.lang.Iterable#forEach [NewApi]
```

I think this is a bit confusing because this is calling the Java
[`Iterable.forEach`](https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer%3C?%20super%20T%3E))
method which was added in Java 8 (and therefore is only available on
API 24 and up), but there is **also** a Kotlin
[`List.forEach`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/for-each.html)
method which is available in all versions of Kotlin (and therefore all
Android versions). Since this is a Kotlin file, at first glance you
would assume this is the Kotlin method - but it's not.

This also doesn't seem to be flagged by Android Studio, but is caught
by Gradle lint on the command line.

#minor-release

PiperOrigin-RevId: 529112610
2023-05-03 17:30:52 +00:00
bachinger
7938978b51 Allow MediaLibraryService to reject the resumption notification
To reliably reject the System UI playback resumption notification on
all API levels (specifically API 30), the backward compatibility layer
needs to return `null` for the library root.

This is not possible in the Media3 implementation. This change allows
an app to return a `LibraryResult.ofError(RESULT_ERROR_NOT_SUPPORTED)`
that then is translated to return null by the backwards compatibility
layer.

Issue: androidx/media#355
Issue: androidx/media#167
Issue: androidx/media#27

See https://developer.android.com/guide/topics/media/media-controls#mediabrowserservice_implementation

PiperOrigin-RevId: 527276529
2023-04-27 12:23:26 +01:00
tonihei
2de89ca2ce Remove unnecessary Activity method overrides in session demo app
The PlayerView methods are documented to only be needed for sphrerical
playbacks, which we are not using in the session demo app.

PiperOrigin-RevId: 525986709
2023-04-24 11:29:46 +01:00
bachinger
c623b965c5 Use DataSourceBitmapLoader in session demo app
Issue: androidx/media#327
PiperOrigin-RevId: 525103046
2023-04-18 18:09:24 +01:00
tonihei
f2cd34ad01 Fix formatting
PiperOrigin-RevId: 524772236
2023-04-17 17:15:13 +01:00
tonihei
be85684dc9 Replace deprecated onBackPressed call
PiperOrigin-RevId: 523361561
2023-04-12 16:47:33 +01:00
tonihei
14ba173dfe Add missing initial update to the subtitle button in the session demo
The button gets only updated after an onTracksChanged callback but
isn't set to the initial state similar to other changes triggered
by callbacks (e.g. updateRepeatSwitchUI)

PiperOrigin-RevId: 522274800
2023-04-11 10:29:32 +01:00
Googler
5af28a980d ...Suppress MissingSuperCall warnings on onBackPressed()...
PiperOrigin-RevId: 520709134
2023-04-05 15:35:22 +01:00
bachinger
d7ef1ab5bd Inline method in PlayerService that is used from on call site only
#cleanup
#minor-release

PiperOrigin-RevId: 505146915
2023-02-01 10:28:52 +00:00
tianyifeng
6ce3421ca7 Post notification for session app when FgS starting exception is caught
PiperOrigin-RevId: 502407886
2023-01-17 02:12:03 +00:00
tonihei
ae8000aeca Replace MediaMetadata folderType by isBrowsable
The folder type has a mix of information about the item. It shows
whether the item is browsable (type != FOLDER_TYPE_NONE) and
which Bluetooth folder type to set for legacy session information.

It's a lot clearer to split this into a boolean isBrowsable and
use the existing mediaType to map back to the bluetooth folder type
where required.

folderType is not marked as deprecated yet as this would be an API
change, which will be done later.

PiperOrigin-RevId: 493544589
2022-12-12 11:32:57 +00:00
michaelkatz
64603cba8d Added cancellation check for MediaBrowserFuture in demo session app
When app is deployed with device's screen being off, MainActivity's onStart is called swiftly by its onStop. The onStop method cancels the browserFuture task which in turn "completes" the task. Upon task "completion", pushRoot() runs and then throws error as it calls get() a cancelled task.

PiperOrigin-RevId: 492416445
2022-12-12 11:03:37 +00:00
bachinger
6a5ac19140 Stop service when app is terminated while the player is paused
If the service ever has been started but is not in the foreground, the
service would be terminated without calling onDestroy(). This is because
when onStartCommand returns START_STICKY [1], the app takes the
responsibility to stop the service.

Note that this change interrupts the user journey when paused, because the
notification is removed. Apps can implement playback resumption [2] to give
the user an option to resume playback after the service has been terminated.

[1] https://developer.android.com/reference/android/app/Service#START_STICKY
[2] https://developer.android.com/guide/topics/media/media-controls#supporting_playback_resumption

Issue: androidx/media#175
#minor-release
PiperOrigin-RevId: 492192690
2022-12-12 10:59:23 +00:00
tianyifeng
cfe36af847 Update targetSdkVersion of demo session app to appTargetSdkVersion
PiperOrigin-RevId: 488884403
2022-11-16 12:18:46 +00:00
tonihei
ab9f0608cd Set matching folder type in Session demo app.
The folder type is useful metadata to understand programmatically
what criterion was used to create the folder.

PiperOrigin-RevId: 486653317
2022-11-08 11:32:18 +00:00
tonihei
5d6d069e4e Set new playlist and start index with one command
PlayableFolderActivity currently uses two seperate commands
to set the playlist and then seek to the requested item.

This is slightly inefficient and also causes analytics
listeners to believe the first item in the playlist was
briefly active.

#minor-release

Issue: androidx/media#180
PiperOrigin-RevId: 480031682
2022-10-17 15:42:30 +00:00
rohks
9a6745431a Use ContextCompat.getMainExecutor when calling MediaBrowser methods
Replacing remaining usage of MoreExecutors.directExecutor. This allows the service to be switched to run in another process and the app still works the same as if it is running in the same process.

Issue: androidx/media#100
PiperOrigin-RevId: 471547177
2022-09-30 17:19:30 +00:00
rohks
d260b0c2a0 Switch incorrectly configured native multidex to legacy for demos
Native multidex can only be used for binaries with minSdkVersion of 21 or higher, but minSdkVersion was specified to 16.

PiperOrigin-RevId: 470004102
2022-09-30 17:05:23 +00:00
bachinger
7fa3f99304 Enable subtitle selection in session demo app
Issue: androidx/media#102
#minor-release
PiperOrigin-RevId: 462391045
2022-08-08 07:56:20 +00:00
bachinger
c9abe70259 Use ContextCompat.getMainExecutor when calling MediaBrowser methods
This allows the service to be switched to run in another process and the app still works the same as if it is running in the same process.

Issue: androidx/media#100
PiperOrigin-RevId: 458460005
2022-07-04 19:50:35 +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
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