You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When playing a MediaItem on Android Auto the queue only contains the currently selected MediaItem #156
Android Auto is using the MediaLibraryService to navigate in the catalogue as you describe. When the user selects an item, Android Auto is preparing the player with the given item via MediaControllerCompat.
In Media3 this preparation request from Android Auto calls MediaLibraryService.Callback.onAddMediaItems(MediaSession mediaSession, ControllerInfo controller, List<MediaItem> mediaItems). The mediaItems parameter contains a single MediaItem that is the one the user has selected.
When you implement onAddMediaItems you return a ListenableFuture<List<MediaItem>>. From your report above I think you now return a future that only contains the selected media item. You can instead return a list of items that is then used set as the playlist/queue.
Said this, there is still an issue because playback always starts at media item index 0. This means when a user selects for instance the third item in a category, you can not set the whole category and then start playback at the third item (media item index 2). I don't have a solution for this yet I'm afraid. I tried some hacky ways but I couldn't find a solution that works reliably.
The only thing you can do for now, is putting the selected item at the begin of the list and all the other items after it. That's a regression to what was possible with media1. So keeping the bug label. We need to think about how we can enable the desired behaviour.
Thanks for answering Marc! Indeed, this does work. I've used your workaround to shuffle the list. Not perfect but far better than having no queue at all.
@marcbaechinger I also find that in the onAddMediaItems method, mediaItems.first().mediaMetadata.extras is always null. Even though I am setting extras in onGetChildren. Is this related or should I file a separate issue? In general mediaMetadata seems to be an empty object, also no title / subtitle for me.
I don't think there is something the Media3 library can do to avoid that as long as Android Auto is using Media1. When AA is browsing your catalogue they are receiving a MediaBrowserCompat.MediaItem from which they take the mediaId to call Callback.prepareByMediaId(String mediaId).
Media3 then receives this call and creates a androidx.media3.MediaItem with it that only contains the mediaId. This is all the information available. You need to resolve the mediaId to a full androidx.media3.MediaItem in onAddMediaItems.
Now with MediaItemsWithStartPosition which you can return in MediaLibraryService.MediaLibrarySession.Callback#onSetMediaItems this is kind of solved, correct?
I wonder what's the best way to prepare additional things with media3. For example I also need to set the playback speed which I persisted, depending on the media items.
And for which I need to query the database which is an async operation.
The only workaround I can imagine right now is to create a delegating player and overwrite all 6 setMediaItem permutations:
Then somehow fetch from the MediaItems where they belong to and then do an runBlocking here to also set the playback speed. But that feels very hacky.
I think you can just defer completing the Future that you return from onSetMediaItems. It's fine to set the speed before the items are set into the player.
For instance:
Create a SettableFuture<MediaItemsWithStartPosition> (and return it)
Load the data for MediaItemsWithStartPosition.
Load the data for speed, shuffleMode and set it to the player.
Set the loaded MediaItemsWithPosition to the settable future. This will prepare the player and then start with the speed you've set earlier.
Activity
marcbaechinger commentedon Aug 18, 2022
Thanks for reporting!
Android Auto is using the
MediaLibraryServiceto navigate in the catalogue as you describe. When the user selects an item, Android Auto is preparing the player with the given item viaMediaControllerCompat.In Media3 this preparation request from Android Auto calls
MediaLibraryService.Callback.onAddMediaItems(MediaSession mediaSession, ControllerInfo controller, List<MediaItem> mediaItems). ThemediaItemsparameter contains a singleMediaItemthat is the one the user has selected.When you implement
onAddMediaItemsyou return aListenableFuture<List<MediaItem>>. From your report above I think you now return a future that only contains the selected media item. You can instead return a list of items that is then used set as the playlist/queue.Said this, there is still an issue because playback always starts at media item index 0. This means when a user selects for instance the third item in a category, you can not set the whole category and then start playback at the third item (media item index 2). I don't have a solution for this yet I'm afraid. I tried some hacky ways but I couldn't find a solution that works reliably.
The only thing you can do for now, is putting the selected item at the begin of the list and all the other items after it. That's a regression to what was possible with media1. So keeping the bug label. We need to think about how we can enable the desired behaviour.
vanniktech commentedon Aug 19, 2022
Thanks for answering Marc! Indeed, this does work. I've used your workaround to shuffle the list. Not perfect but far better than having no queue at all.
vanniktech commentedon Aug 20, 2022
@marcbaechinger I also find that in the
onAddMediaItemsmethod,mediaItems.first().mediaMetadata.extrasis always null. Even though I am setting extras inonGetChildren. Is this related or should I file a separate issue? In generalmediaMetadataseems to be an empty object, also no title / subtitle for me.marcbaechinger commentedon Aug 22, 2022
I don't think there is something the Media3 library can do to avoid that as long as Android Auto is using Media1. When AA is browsing your catalogue they are receiving a
MediaBrowserCompat.MediaItemfrom which they take themediaIdto callCallback.prepareByMediaId(String mediaId).Media3 then receives this call and creates a
androidx.media3.MediaItemwith it that only contains themediaId. This is all the information available. You need to resolve themediaIdto a fullandroidx.media3.MediaIteminonAddMediaItems.PaulWoitaschek commentedon May 16, 2023
Now with
MediaItemsWithStartPositionwhich you can return inMediaLibraryService.MediaLibrarySession.Callback#onSetMediaItemsthis is kind of solved, correct?I wonder what's the best way to prepare additional things with media3. For example I also need to set the playback speed which I persisted, depending on the media items.
And for which I need to query the database which is an async operation.
The only workaround I can imagine right now is to create a delegating player and overwrite all 6 setMediaItem permutations:
Then somehow fetch from the MediaItems where they belong to and then do an runBlocking here to also set the playback speed. But that feels very hacky.
marcbaechinger commentedon May 16, 2023
I think you can just defer completing the
Futurethat you return fromonSetMediaItems. It's fine to set the speed before the items are set into the player.For instance:
SettableFuture<MediaItemsWithStartPosition>(and return it)MediaItemsWithStartPosition.MediaItemsWithPositionto the settable future. This will prepare the player and then start with the speed you've set earlier.I haven't tried but I think that should work.
marcbaechinger commentedon Jun 1, 2023
Closing as the initial issue is fixed.