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));
});
}
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);
});
}
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);
}
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);
}
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);
}
Aggregations