Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Custom Browse Actions with Media3 MediaLibraryService #1474

Open
icutvaric opened this issue Jun 19, 2024 · 4 comments
Open

Implement Custom Browse Actions with Media3 MediaLibraryService #1474

icutvaric opened this issue Jun 19, 2024 · 4 comments
Assignees

Comments

@icutvaric
Copy link

How can we implement same Custom Browse Actions described in here https://developer.android.com/training/cars/media#how_to_implement_custom_browse_actions
with Media3 MediaLibraryService?

@tonihei
Copy link
Collaborator

tonihei commented Jun 19, 2024

We are in the process of adding this feature and we can use this issue to track this effort publicly. Unfortunately, we missed that Android Automotive published guidelines for this already without waiting for the Media3 implementation, so apologies for the feature gap.

@tonihei tonihei assigned tonihei and marcbaechinger and unassigned tonihei Jun 19, 2024
@tonihei tonihei changed the title How to implement Custom Browse Actions with Media3 MediaLibraryService Implement Custom Browse Actions with Media3 MediaLibraryService Jun 19, 2024
@Tolriq
Copy link
Contributor

Tolriq commented Jun 19, 2024

@tonihei From my reading about that feature it was for Android Automotive and not Android Auto.

Did you meant that or will this be supported on Android Auto too?

@icutvaric
Copy link
Author

@tonihei thanks for the clarification. Do you know approx. when can we expect this feature?

@tonihei
Copy link
Collaborator

tonihei commented Jun 20, 2024

Yes, I meant Automotive (fixed my post too). And we can't provide concrete timelines, but unfortunately it won't be part of the upcoming 1.4.0 release. We'll try to get it in as soon as possible afterwards.

copybara-service bot pushed a commit that referenced this issue Sep 19, 2024
When sending a custom command with `browser.sendCustomCommand` when
connected to a legacy browser service, the custom command was delivered to `MediaSessionCompat.Callback.onCustomAction` instead of the service method
`onCustomAction`. The difference is that the service version can return an
async response with a bundle, while the session callback version doesn't
have a return value.

Hence, the service method was never called and it wasn't possible to send
a reponse or signal an error back to the browser. The resulting
`ListanableFuture` simply always immediately resolved to a success.

This change overrides `ListenableFuture<SessionResult> sendCustomCommand(SessionCommand command, Bundle args)` in
`MediaBrowserImplLegacy` to use the `MediaBrowserCompat` method to send
instead of the `MediaControlleCompat` method that was used by the subclass
`MediaControllerImplLegacy`. This involves the service callback instead of the
session callback and enables `MediaBrowser` to get the actual return value
from the legacy service.

Issue: #1474
#cherrypick
PiperOrigin-RevId: 676519314
copybara-service bot pushed a commit that referenced this issue Sep 25, 2024
Note that unlike the legacy implementation, custom media items
commands can be used for any media items with Media3 API. This
includes `MediaItem` instances that are received from sources
different to `MediaLibraryService` methods.

Hence when connected against a Media3 session these custom commands
can be used with a `MediaController` as well as with a `MediaBrowser`.

Interoperability with `MediaBrowserServiceCompat` will
be added in a follow up CL.

Issue: #1474
#cherrypick
PiperOrigin-RevId: 678782860
copybara-service bot pushed a commit that referenced this issue Sep 26, 2024
The max number of commands for media items of a browser or controller
can be configured with `setMaxCommandsForMediaItems(int)` on
`MediaController.Builder` and `MediaBrowser.Builder`. An app that has
only limited space for displaying commands can hint this limit to the
session.

A session can receive the value of a connected browser or controller
through `getMaxCommandsForMediaItems()` of a `ControllerInfo` that
is passed into every callback method. The session can then pick the most
sensible commands instead of making the browser app truncating the commands
rather randomly.

When a `MediaBrowser` is connected against a legacy `MediaBrowserServiceCompat`,
the max number of commands is automatically added to the root hints. Conversely,
the value passed in with the root hints to `MediaLibraryService` by a legacy
`MediaBrowserCompat`, is read into `ControllerInfo` like for a Media3 browser.

Issue: #1474

#cherrypick

PiperOrigin-RevId: 679076506
copybara-service bot pushed a commit that referenced this issue Oct 8, 2024
When calling `MediaController.getCommandButtonForMediaItem(MediaItem)`
command buttons with custom commands that are not available
shouldn't be advertised to the controller when connected to
a Media3 session.

In contrast, when connected to a legacy session, available commands
are not enforced when advertising commands. Similarly, when sending
a custom commands that is referenced by a command button for media
items, sending is permitted without the command being available.

This is required because available commands match to custom actions
in `PlaybackStateCompat` of the legacy session. Adding commands for
media items to custom action of the `PlaybackStateCompat` would
interfere with other use cases.

Issue: #1474
#cherrypick
PiperOrigin-RevId: 683717723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants