diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1127c55a4b2..1ff42ee1e30 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..3c05b211983 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,26 @@ package org.schabi.newpipe.player.mediabrowser; +import static org.schabi.newpipe.MainActivity.DEBUG; + +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 +33,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 +43,29 @@ 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) { + if (DEBUG) { + 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) { + if (DEBUG) { + Log.d(TAG, String.format("MediaBrowserService.onLoadChildren(%s)", parentId)); + } + + final List mediaItems = new ArrayList<>(); + + return Single.just(mediaItems); + } }