Search in sources :

Example 1 with LibraryParams

use of androidx.media3.session.MediaLibraryService.LibraryParams in project media by androidx.

the class MediaLibraryServiceLegacyStub method onSubscribe.

// TODO(b/192455639): Optimize potential multiple calls of
// MediaBrowserCompat.SubscriptionCallback#onChildrenLoaded() with the same
// content.
@Override
public void onSubscribe(String id, Bundle option) {
    @Nullable ControllerInfo controller = getCurrentController();
    if (controller == null) {
        return;
    }
    if (TextUtils.isEmpty(id)) {
        Log.w(TAG, "onSubscribe(): Ignoring empty id from " + controller);
        return;
    }
    postOrRun(librarySessionImpl.getApplicationHandler(), () -> {
        if (!getConnectedControllersManager().isSessionCommandAvailable(controller, SessionCommand.COMMAND_CODE_LIBRARY_SUBSCRIBE)) {
            return;
        }
        @Nullable LibraryParams params = MediaUtils.convertToLibraryParams(librarySessionImpl.getContext(), option);
        ignoreFuture(librarySessionImpl.onSubscribeOnHandler(controller, id, params));
    });
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable) ControllerInfo(androidx.media3.session.MediaSession.ControllerInfo)

Example 2 with LibraryParams

use of androidx.media3.session.MediaLibraryService.LibraryParams in project media by androidx.

the class MediaLibraryServiceLegacyStub method onLoadChildren.

@Override
public void onLoadChildren(String parentId, Result<List<MediaBrowserCompat.MediaItem>> result, @Nullable Bundle options) {
    @Nullable ControllerInfo controller = getCurrentController();
    if (controller == null) {
        result.sendError(/* extras= */
        null);
        return;
    }
    if (TextUtils.isEmpty(parentId)) {
        Log.w(TAG, "onLoadChildren(): Ignoring empty parentId from " + controller);
        result.sendError(/* extras= */
        null);
        return;
    }
    result.detach();
    postOrRun(librarySessionImpl.getApplicationHandler(), () -> {
        if (!getConnectedControllersManager().isSessionCommandAvailable(controller, SessionCommand.COMMAND_CODE_LIBRARY_GET_CHILDREN)) {
            result.sendError(/* extras= */
            null);
            return;
        }
        if (options != null) {
            options.setClassLoader(librarySessionImpl.getContext().getClassLoader());
            try {
                int page = options.getInt(EXTRA_PAGE);
                int pageSize = options.getInt(EXTRA_PAGE_SIZE);
                if (page >= 0 && pageSize > 0) {
                    // Requesting the list of children through pagination.
                    @Nullable LibraryParams params = MediaUtils.convertToLibraryParams(librarySessionImpl.getContext(), options);
                    ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> future = librarySessionImpl.onGetChildrenOnHandler(controller, parentId, page, pageSize, params);
                    sendLibraryResultWithMediaItemsWhenReady(result, future);
                    return;
                }
            // Cannot distinguish onLoadChildren() why it's called either by
            // {@link MediaBrowserCompat#subscribe()} or
            // {@link MediaBrowserServiceCompat#notifyChildrenChanged}.
            } catch (BadParcelableException e) {
            // pass-through.
            }
        }
        // A MediaBrowserCompat called loadChildren with no pagination option.
        ListenableFuture<LibraryResult<ImmutableList<MediaItem>>> future = librarySessionImpl.onGetChildrenOnHandler(controller, parentId, /* page= */
        0, /* pageSize= */
        Integer.MAX_VALUE, /* params= */
        null);
        sendLibraryResultWithMediaItemsWhenReady(result, future);
    });
}
Also used : MediaItem(androidx.media3.common.MediaItem) LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable) ControllerInfo(androidx.media3.session.MediaSession.ControllerInfo) BadParcelableException(android.os.BadParcelableException)

Example 3 with LibraryParams

use of androidx.media3.session.MediaLibraryService.LibraryParams in project media by androidx.

the class MediaSessionStub method subscribe.

@Override
public void subscribe(@Nullable IMediaController caller, int seq, String parentId, @Nullable Bundle libraryParamsBundle) {
    if (caller == null) {
        return;
    }
    if (TextUtils.isEmpty(parentId)) {
        Log.w(TAG, "subscribe(): Ignoring empty parentId");
        return;
    }
    @Nullable LibraryParams libraryParams = BundleableUtil.fromNullableBundle(LibraryParams.CREATOR, libraryParamsBundle);
    dispatchSessionTaskWithLibrarySessionCommand(caller, seq, COMMAND_CODE_LIBRARY_SUBSCRIBE, (librarySessionImpl, controller) -> librarySessionImpl.onSubscribeOnHandler(controller, parentId, libraryParams), MediaSessionStub::sendLibraryResultWhenReady);
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable)

Example 4 with LibraryParams

use of androidx.media3.session.MediaLibraryService.LibraryParams in project media by androidx.

the class MediaSessionStub method getSearchResult.

@Override
public void getSearchResult(@Nullable IMediaController caller, int seq, String query, int page, int pageSize, @Nullable Bundle libraryParamsBundle) {
    if (caller == null) {
        return;
    }
    if (TextUtils.isEmpty(query)) {
        Log.w(TAG, "getSearchResult(): Ignoring empty query");
        return;
    }
    if (page < 0) {
        Log.w(TAG, "getSearchResult(): Ignoring negative page");
        return;
    }
    if (pageSize < 1) {
        Log.w(TAG, "getSearchResult(): Ignoring pageSize less than 1");
        return;
    }
    @Nullable LibraryParams libraryParams = BundleableUtil.fromNullableBundle(LibraryParams.CREATOR, libraryParamsBundle);
    dispatchSessionTaskWithLibrarySessionCommand(caller, seq, COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT, (librarySessionImpl, controller) -> librarySessionImpl.onGetSearchResultOnHandler(controller, query, page, pageSize, libraryParams), MediaSessionStub::sendLibraryResultWhenReady);
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable)

Example 5 with LibraryParams

use of androidx.media3.session.MediaLibraryService.LibraryParams in project media by androidx.

the class MediaSessionStub method search.

@Override
public void search(@Nullable IMediaController caller, int seq, String query, @Nullable Bundle libraryParamsBundle) {
    if (caller == null) {
        return;
    }
    if (TextUtils.isEmpty(query)) {
        Log.w(TAG, "search(): Ignoring empty query");
        return;
    }
    @Nullable LibraryParams libraryParams = BundleableUtil.fromNullableBundle(LibraryParams.CREATOR, libraryParamsBundle);
    dispatchSessionTaskWithLibrarySessionCommand(caller, seq, COMMAND_CODE_LIBRARY_SEARCH, (librarySessionImpl, controller) -> librarySessionImpl.onSearchOnHandler(controller, query, libraryParams), MediaSessionStub::sendLibraryResultWhenReady);
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable)

Aggregations

LibraryParams (androidx.media3.session.MediaLibraryService.LibraryParams)29 Test (org.junit.Test)19 LargeTest (androidx.test.filters.LargeTest)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 Nullable (androidx.annotation.Nullable)13 Bundle (android.os.Bundle)10 ImmutableList (com.google.common.collect.ImmutableList)10 MediaItem (androidx.media3.common.MediaItem)9 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Proxy (androidx.media3.session.MockMediaBrowserServiceCompat.Proxy)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ControllerInfo (androidx.media3.session.MediaSession.ControllerInfo)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Context (android.content.Context)1 BadParcelableException (android.os.BadParcelableException)1 ItemCallback (android.support.v4.media.MediaBrowserCompat.ItemCallback)1 SubscriptionCallback (android.support.v4.media.MediaBrowserCompat.SubscriptionCallback)1