1

I am attempting to create a simple audio app and am referencing Google's MediaBrowserService example. My question is really grasping the concept behind MediaBrowserServiceCompat.onLoadChildren() and MediaSessionCompat.Callback methods onAddQueueItem and onRemoveQueueItem

@Override
public void onLoadChildren(@NonNull final String parentMediaId,
        @NonNull final Result<List<MediaBrowserCompat.MediaItem>> result) {

    Log.d(TAG, "onLoadChildren(): ------------------->");

    result.sendResult(MusicLibrary.getMediaItems());
}

@Override
public void onAddQueueItem(MediaDescriptionCompat description) {
    mPlaylist.add(new MediaSessionCompat.QueueItem(description, description.hashCode()));
    mQueueIndex = (mQueueIndex == -1) ? 0 : mQueueIndex;
    mSession.setQueue(mPlaylist);
}

@Override
public void onRemoveQueueItem(MediaDescriptionCompat description) {
    mPlaylist.remove(new MediaSessionCompat.QueueItem(description, description.hashCode()));
    mQueueIndex = (mPlaylist.isEmpty()) ? -1 : mQueueIndex;
    mSession.setQueue(mPlaylist);
}

Mass confusion sets when I try to reconcile onAddQueueItem and onRemoveQueueItem methods with onLoadChildren. Does the onAddQueueItem() automatically generate MediaBrowserCompat.MediaItems that were sent/made available via the result.sendResult() in onLoadChildren() method? or am I confusing myself even further by trying to link the two ? if anyone has blogs/articles/youtube videos that will help broaden my understanding, it be much obliged.

0 Answers0