diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d86dde6df6..11a30578a77 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -64,6 +64,9 @@ + + + > result) { + result.detach(); + final var disposable = mediaBrowserConnector.onLoadChildren(parentId) + .subscribe(result::sendResult); + compositeDisposableLoadChildren.add(disposable); + } } diff --git a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java index 6fc61c3d748..d18baead087 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java @@ -1,13 +1,24 @@ package org.schabi.newpipe.player.mediabrowser; +import android.os.Bundle; +import android.support.v4.media.MediaBrowserCompat; +import android.support.v4.media.MediaBrowserCompat.MediaItem; import android.support.v4.media.session.MediaSessionCompat; +import android.util.Log; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.media.MediaBrowserServiceCompat; import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; import org.schabi.newpipe.player.PlayerService; +import java.util.ArrayList; +import java.util.List; + +import io.reactivex.rxjava3.core.Single; + public class MediaBrowserConnector { private static final String TAG = MediaBrowserConnector.class.getSimpleName(); @@ -20,6 +31,7 @@ public MediaBrowserConnector(@NonNull final PlayerService playerService) { mediaSession = new MediaSessionCompat(playerService, TAG); sessionConnector = new MediaSessionConnector(mediaSession); sessionConnector.setMetadataDeduplicationEnabled(true); + playerService.setSessionToken(mediaSession.getSessionToken()); } public @NonNull MediaSessionConnector getSessionConnector() { @@ -29,4 +41,25 @@ public MediaBrowserConnector(@NonNull final PlayerService playerService) { public void release() { mediaSession.release(); } + + @NonNull + private static final String MY_MEDIA_ROOT_ID = "media_root_id"; + + @Nullable + public MediaBrowserServiceCompat.BrowserRoot onGetRoot(@NonNull final String clientPackageName, + final int clientUid, + @Nullable final Bundle rootHints) { + Log.d(TAG, String.format("MediaBrowserService.onGetRoot(%s, %s, %s)", + clientPackageName, clientUid, rootHints)); + + return new MediaBrowserServiceCompat.BrowserRoot(MY_MEDIA_ROOT_ID, null); + } + + public Single> onLoadChildren(@NonNull final String parentId) { + Log.d(TAG, String.format("MediaBrowserService.onLoadChildren(%s)", parentId)); + + final List mediaItems = new ArrayList<>(); + + return Single.just(mediaItems); + } }