media
media copied to clipboard
demo-session crashing when connected from "Media Controller Tester"
Demo session sample app is crashing when conneced from https://github.com/googlesamples/android-media-controller
Tested against both release and main branches
Crash with Android API 24 On API 26 & 28 it doesn’t crash, but returns no results when browsing Works with Android API 29 & 30
Step to reproduce deploy both apps on device launch media controller test app click "control" on Media3 Session Demo in the list
2022-05-20 11:50:09.972 9872-9872/androidx.media3.demo.session E/AndroidRuntime: FATAL EXCEPTION: main
Process: androidx.media3.demo.session, PID: 9872
java.lang.UnsupportedOperationException: It is not supported to send an error for [rootID]
at androidx.media.MediaBrowserServiceCompat$Result.onErrorSent(MediaBrowserServiceCompat.java:944)
at androidx.media.MediaBrowserServiceCompat$Result.sendError(MediaBrowserServiceCompat.java:889)
at androidx.media3.session.MediaLibraryServiceLegacyStub.onLoadChildren(MediaLibraryServiceLegacyStub.java:178)
at androidx.media3.session.MediaLibraryServiceLegacyStub.onLoadChildren(MediaLibraryServiceLegacyStub.java:168)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21.onLoadChildren(MediaBrowserServiceCompat.java:427)
at androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$MediaBrowserServiceApi21.onLoadChildren(MediaBrowserServiceCompat.java:518)
at android.service.media.MediaBrowserService.performLoadChildren(MediaBrowserService.java:662)
at android.service.media.MediaBrowserService.addSubscription(MediaBrowserService.java:600)
at android.service.media.MediaBrowserService.-wrap3(MediaBrowserService.java)
at android.service.media.MediaBrowserService$ServiceBinder$3.run(MediaBrowserService.java:272)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Thanks for reporting!
I think this is because the PlaybackService
of the session demo advertises COMMAND_CODE_LIBRARY_SUBSCRIBE
but actually doesn't override MediaLibrarySessionCallback.subscribe()
. We already have implemented subscribe
in the meanwhile and this will be fixed in the main branch soon and part of the next release.
see this commit also.
Ok thanks. I'll give it a try and let you know
mmmh, still crashing the same way.
I think the issue is because controller
is null
https://github.com/androidx/media/blob/72a4fb082d9e68ecd7db3ff87b19f4232a5991d2/libraries/session/src/main/java/androidx/media3/session/MediaLibraryServiceLegacyStub.java#L178
Thanks for checking and the feedback.
I think there are two issues. The first is the crash at connection time that you report and the second is that browsing the category tree isn't working.
1) Crash at connection to session
When I test with API 27 with Android 13 (SP2A.220505.002) and T (TP1A.220519.003) I can succefully connect with the media controller test
app that is using the legacy media session API and with the media controller test
app that is using the Media3 API. After connecting I can see the current state of the player, the available actions and I can use the functionality of MediaSessionCompat
. transport controls including custom actions.
I see you reported the crash above for API 24 so I'm going to test with that API as well. Can you confirm this only happens on API 24?
2) Browsing not working
I noticed that with the media test controller
app that is using the legacy controller API, I can connect but the MediaBrowserService
functionality is not working properly. I wasn't successful to browse the tree with any app I tried of which I know browsing works with other clients (UAMP, SoundCloud). I found that it works when I set a break point in the session demo app in onGetChildren
. So it looks like there is a threading issue somewhere.
When testing with UAMP that is using the legacy MediaSession still I get the same results (meaning I can not browse UAMP or Soundcloud but transport controls and metadata work).
Can you browse your app with the media controller test
app (like MediabrowserCOmpat accessing your MediaBrowserCompatService)?
Ok
for the connection crash, it seems to only happens with API 24 and API 26 (probably lower API too) API 27+ don't throw the UnsupportedOperationException
for the browsing issue, it seems to only works on API 28+ (even with onSubscribe implemented)
I can browse my app, or the demo-session app with media controller test
which (by the look of the deps) is still using MediabrowseCompat, only on API 28+ devices
Can confirm that this issue is reproducible on all Samsungs with Samsung Experience ROM (pre-One UI, also SDK 24), and it directly happens if you try to connect a MediaController
directly to your application's MediaLibraryService
.
Is there any workaround of it at the moment? Production users are reporting about the issues on such devices, and there is ~~no possible way to override onSubscribe
without disabling MediaLibraryService
features (like losing Android Auto support)~~
Update: my bad, you actually can override both onSubscribe
and onUnsubscribe
, so I just replaced them with Futures.immediateFuture(LibraryResult.ofVoid())
so the application won't crash on SE7. I hope it works.
I can not repro the crash when using an emulator running Android 7/API 24.
There is a bug in the media controller app that does not allow to browse the categories. Once this bug is fixed, I can connect to the session demo and navigate through the library. I can also start and pause playback of the current item and add a new item for playback when using the browser.
I have file a pull request against the media controller app to fix this: https://github.com/googlesamples/android-media-controller/pull/50