media
media copied to clipboard
Make MediaControllerImplBase local binder aware
The session->controller data flow already nicely avoids bundling if we don't have to bundle by skipping the entire PlayerInfo object which contains almost everything. But in the controller->session data flow, some complex objects (MediaMetadata, MediaItem and TrackSelectionParameters) were always bundled even if we don't have to. This change skips bundling for these object and should improve performance significantly when sending large lists of MediaItems to a session in the same process.
For some background, my app has a controller.setMediaItems() call in a onclick listener, and Play Console has been complaining about ANRs in the unbundling code:
at androidx.media3.common.MediaMetadata$Builder.build (MediaMetadata.java:624)
at androidx.media3.common.MediaMetadata.fromBundle (MediaMetadata.java:1541)
at androidx.media3.common.MediaItem.fromBundle (MediaItem.java:2463)
at androidx.media3.common.util.BundleCollectionUtil.fromBundleList (BundleCollectionUtil.java:67)
at androidx.media3.session.MediaSessionStub.setMediaItemsWithStartIndex (MediaSessionStub.java:1113)
at androidx.media3.session.MediaControllerImplBase.lambda$setMediaItems$27 (MediaControllerImplBase.java:899)
at androidx.media3.session.MediaControllerImplBase.dispatchRemoteSessionTask (MediaControllerImplBase.java:392)
at androidx.media3.session.MediaControllerImplBase.dispatchRemoteSessionTaskWithPlayerCommand (MediaControllerImplBase.java:331)
at androidx.media3.session.MediaControllerImplBase.setMediaItems (MediaControllerImplBase.java:897)
at androidx.media3.session.MediaController.setMediaItems (MediaController.java:1301)
at org.akanework.gramophone.ui.adapters.SongAdapter.onClick (SongAdapter.kt:163)