4

When I open activity 1 (Main/Launcher activity of the app), that includes MediaBrowser connection, MediaBrowser.subscribe works ok (onChildrenLoaded is being called after it), but when I opened some other activity (number 2) from activity 1 (using button click listener and intent) and then close this activity 2, MediaBrowser.subscribe stops working - onChildrenLoaded is NOT being called after subscribing, so after activity 2 finishes onConnected of SubscriptionCallback (of activity 1) & mMediaBrowser.subscribe(MEDIA_ID_ROOT, mSubscriptionCallback); are being called but my items aren't updated because onChildrenLoaded is never triggered

private MediaBrowserCompat.ConnectionCallback mConnectionCallback =
            new MediaBrowserCompat.ConnectionCallback() {
                @Override
                public void onConnected() {
                    Log.i(TAG, "onConnected");
                    mMediaBrowser.unsubscribe(MEDIA_ID_ROOT, mSubscriptionCallback);
                    mMediaBrowser.subscribe(MEDIA_ID_ROOT, mSubscriptionCallback);

                }
            };

private MediaBrowserCompat.SubscriptionCallback mSubscriptionCallback = new MediaBrowserCompat.SubscriptionCallback() {

        @Override
        public void onChildrenLoaded(String parentId, List<MediaBrowserCompat.MediaItem> children) {
            Log.i(TAG, "onChildrenLoaded"); // isn't being called on android 6.0.1 after I got back to this activity from other
        if (children != null) {
            if (mMediaItems != null) {
                mMediaItems.clear();
                mMediaItems = null;
            }
            mMediaItems = children;
            if (mAdapter == null) {
                mAdapter = new Adapter();
                mRecyclerView.setAdapter(mAdapter);
            } else {
                mAdapter.notifyDataSetChanged();
            }
        }
        }

        @Override
        public void onError(String id) {
            Log.i(TAG, "SubscriptionCallback onError");
        }
    };

But it works ok for 4.4.4 Android (no such problems)

Update

It seems like I found this problem on Google Bugs (some Developer reported it): https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=-has%3Asubcomponent%20-has%3Atarget%20emulator%20.&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=232455

But there is no solution

Also have such error:

04-02 18:25:55.519 11250-11250/com.android.player W/MBServiceCompat: removeSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.519 11250-11250/com.android.player W/MBServiceCompat: addSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.525 11250-11250/com.android.player W/MBServiceCompat: removeSubscription for callback that isn't registered id=hhhh
04-02 18:25:55.525 11250-11250/com.android.player W/MBServiceCompat: addSubscription for callback that isn't registered id=hhhh

Update 2

Also there

https://github.com/googlesamples/android-UniversalMusicPlayer/issues/92

mb last comment of this link will solve this problem for me too

Update 3

Yeah, github.com/googlesamples/android-UniversalMusicPlayer/issues/92#issuecomment-287668132 SOLVED the problem:

move MediaBrowserCompat.connect() from onStart() to onCreate(), and move MediaBrowserCompat.disconnect() from onStop() to onDestroy(). It works now.

user924
  • 8,146
  • 7
  • 57
  • 139

3 Answers3

0
  1. This issue was marked as fixed at google issuetracker in Support Lib v 25.4.0
  2. solution to

move MediaBrowserCompat.connect() from onStart() to onCreate(), and move MediaBrowserCompat.disconnect() from onStop() to onDestroy()

works for me.

  1. when I moved them and fixed the original issue, the next one appeared: MediaController Callback didn't work. It seems for me as caused by the similar bug. So I have moved call to unsubscribe() to onDestroy() too, and everything works now.

So my code now looks like:

protected void onCreate(Bundle savedInstanceState) {
    ...    
    mediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, AudioService.class),
            connCallbacks,
            null);
    mediaBrowser.connect();
    ...
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    MediaControllerCompat cntrlr = MediaControllerCompat.getMediaController(this);
    if(cntrlr != null) {
        cntrlr.unregisterCallback(cntrlrCallback);
    }
    if(mediaBrowser.isConnected()) {
        mediaBrowser.unsubscribe(mediaBrowser.getRoot());
        mediaBrowser.disconnect();
    }
}
Community
  • 1
  • 1
B-GangsteR
  • 2,534
  • 22
  • 34
0

Temporary solution:

move MediaBrowserCompat.connect() from onStart() to onCreate(), and move MediaBrowserCompat.disconnect() from onStop() to onDestroy(). It works now.

Must be fixed in v25.4.0: https://issuetracker.google.com/issues/37133265#comment3

user924
  • 8,146
  • 7
  • 57
  • 139
0

With reference to Google issue tracker.

Issue is fixed and released in 25.4.0 version of support library.

If any issue persists, please report at Google issue tracker they will re-open to examine.

Prags
  • 2,457
  • 2
  • 21
  • 38