Alex Kombo
Alex Kombo

Reputation: 3356

onLoadChildren sent null list for id root on MediaBrowserServiceCompat Service

I keep getting this error on some devices whenever the user tries to play some tracks using my media player.

Fatal Exception: java.lang.IllegalStateException: onLoadChildren sent null list for id root
       at android.service.media.MediaBrowserService$3.onResultSent(MediaBrowserService.java:473)
       at android.service.media.MediaBrowserService$3.onResultSent(MediaBrowserService.java:469)
       at android.service.media.MediaBrowserService$Result.sendResult(MediaBrowserService.java:131)
       at android.support.v4.media.MediaBrowserServiceCompatApi21$ResultWrapper.sendResult(MediaBrowserServiceCompatApi21.java:77)
       at android.support.v4.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$3.onResultSent(MediaBrowserServiceCompat.java:366)
       at android.support.v4.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21$3.onResultSent(MediaBrowserServiceCompat.java:354)
       at android.support.v4.media.MediaBrowserServiceCompat$Result.sendResult(MediaBrowserServiceCompat.java:606)
       at com.radioafrica.music.playback.MusicPlaybackService.onLoadChildren(MusicPlaybackService.java:102)
       at android.support.v4.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi21.onLoadChildren(MediaBrowserServiceCompat.java:374)
       at android.support.v4.media.MediaBrowserServiceCompatApi21$MediaBrowserServiceAdaptor.onLoadChildren(MediaBrowserServiceCompatApi21.java:128)
       at android.service.media.MediaBrowserService.performLoadChildren(MediaBrowserService.java:495)
       at android.service.media.MediaBrowserService.addSubscription(MediaBrowserService.java:459)
       at android.service.media.MediaBrowserService.access$400(MediaBrowserService.java:68)
       at android.service.media.MediaBrowserService$ServiceBinder$3.run(MediaBrowserService.java:247)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7325)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

My code for the onLoadChildren method is:

 @Override
    public void onLoadChildren(@NonNull String s, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
        result.sendResult(null);
    }

What causes this to fail for some users and work for others?

Upvotes: 2

Views: 1326

Answers (3)

emad pirayesh
emad pirayesh

Reputation: 704

i replace

result.sendResult(null);

with

 result.sendResult(Collections.<MediaBrowserCompat.MediaItem>emptyList()); 

in onloadChildren method issue solved for me

Upvotes: 0

J&#250;lio Zynger
J&#250;lio Zynger

Reputation: 1178

Got the following answer from a Googler in this issue on the tracker:

... this is fixed issue after N, and for pre-N devices, if both browser and browser service apps are using support library, it shouldn't happen.

Upvotes: 0

jacob.zimmerman
jacob.zimmerman

Reputation: 119

I realize that this is an older question, but I recently came across this issue and wanted to leave an answer.

It depends on what you are sending as your browser root in onGetRoot. I was following this documentation for controlling connections with onGetRoot, which suggests having a separate empty root for clients that have media control but not browse access. When that root is requested, you need to send an empty list, not null. Null is reserved for an invalid media id according to the documentation for MediaBrowserService.onLoadChildren

From what I can tell, pre-N devices do not handle the null value appropriately. Here is the source code for the exception you see on Android M. Notice that sending a null list triggers this exception. Since newer bluetooth stacks support media browsing, the bluetooth package may be trying to connect to your service (there are plenty of Samsung devices like the Galaxy Note 4 that support bluetooth browse AND are running Android M, which would crash here).

Upvotes: 5

Related Questions