use of androidx.media3.common.util.BundleableUtil.fromNullableBundle in project media by androidx.
the class ConnectionState method fromBundle.
private static ConnectionState fromBundle(Bundle bundle) {
int version = bundle.getInt(keyForField(FIELD_VERSION), /* defaultValue= */
0);
IBinder sessionBinder = checkNotNull(BundleCompat.getBinder(bundle, keyForField(FIELD_SESSION_BINDER)));
@Nullable PendingIntent sessionActivity = bundle.getParcelable(keyForField(FIELD_SESSION_ACTIVITY));
SessionCommands sessionCommands = BundleableUtil.fromNullableBundle(SessionCommands.CREATOR, bundle.getBundle(keyForField(FIELD_SESSION_COMMANDS)), SessionCommands.EMPTY);
Player.Commands playerCommandsFromPlayer = BundleableUtil.fromNullableBundle(Player.Commands.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYER_COMMANDS_FROM_PLAYER)), Player.Commands.EMPTY);
Player.Commands playerCommandsFromSession = BundleableUtil.fromNullableBundle(Player.Commands.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYER_COMMANDS_FROM_SESSION)), Player.Commands.EMPTY);
@Nullable Bundle tokenExtras = bundle.getBundle(keyForField(FIELD_TOKEN_EXTRAS));
PlayerInfo playerInfo = BundleableUtil.fromNullableBundle(PlayerInfo.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYER_INFO)), PlayerInfo.DEFAULT);
return new ConnectionState(version, IMediaSession.Stub.asInterface(sessionBinder), sessionActivity, sessionCommands, playerCommandsFromSession, playerCommandsFromPlayer, tokenExtras == null ? Bundle.EMPTY : tokenExtras, playerInfo);
}
use of androidx.media3.common.util.BundleableUtil.fromNullableBundle in project media by androidx.
the class SessionPositionInfo method fromBundle.
private static SessionPositionInfo fromBundle(Bundle bundle) {
PositionInfo positionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_POSITION_INFO)), /* defaultValue= */
DEFAULT_POSITION_INFO);
boolean isPlayingAd = bundle.getBoolean(keyForField(FIELD_IS_PLAYING_AD), /* defaultValue= */
false);
long eventTimeMs = bundle.getLong(keyForField(FIELD_EVENT_TIME_MS), /* defaultValue= */
C.TIME_UNSET);
long durationMs = bundle.getLong(keyForField(FIELD_DURATION_MS), /* defaultValue= */
C.TIME_UNSET);
long bufferedPositionMs = bundle.getLong(keyForField(FIELD_BUFFERED_POSITION_MS), /* defaultValue= */
C.TIME_UNSET);
int bufferedPercentage = bundle.getInt(keyForField(FIELD_BUFFERED_PERCENTAGE), /* defaultValue= */
0);
long totalBufferedDurationMs = bundle.getLong(keyForField(FIELD_TOTAL_BUFFERED_DURATION_MS), /* defaultValue= */
0);
long currentLiveOffsetMs = bundle.getLong(keyForField(FIELD_CURRENT_LIVE_OFFSET_MS), /* defaultValue= */
C.TIME_UNSET);
long contentDurationMs = bundle.getLong(keyForField(FIELD_CONTENT_DURATION_MS), /* defaultValue= */
C.TIME_UNSET);
long contentBufferedPositionMs = bundle.getLong(keyForField(FIELD_CONTENT_BUFFERED_POSITION_MS), /* defaultValue= */
C.TIME_UNSET);
return new SessionPositionInfo(positionInfo, isPlayingAd, eventTimeMs, durationMs, bufferedPositionMs, bufferedPercentage, totalBufferedDurationMs, currentLiveOffsetMs, contentDurationMs, contentBufferedPositionMs);
}
use of androidx.media3.common.util.BundleableUtil.fromNullableBundle in project media by androidx.
the class MediaSessionStub method getChildren.
@Override
public void getChildren(@Nullable IMediaController caller, int seq, String parentId, int page, int pageSize, @Nullable Bundle libraryParamsBundle) throws RuntimeException {
if (caller == null) {
return;
}
if (TextUtils.isEmpty(parentId)) {
Log.w(TAG, "getChildren(): Ignoring empty parentId");
return;
}
if (page < 0) {
Log.w(TAG, "getChildren(): Ignoring negative page");
return;
}
if (pageSize < 1) {
Log.w(TAG, "getChildren(): Ignoring pageSize less than 1");
return;
}
@Nullable LibraryParams libraryParams = BundleableUtil.fromNullableBundle(LibraryParams.CREATOR, libraryParamsBundle);
dispatchSessionTaskWithLibrarySessionCommand(caller, seq, COMMAND_CODE_LIBRARY_GET_CHILDREN, (librarySessionImpl, controller) -> librarySessionImpl.onGetChildrenOnHandler(controller, parentId, page, pageSize, libraryParams), MediaSessionStub::sendLibraryResultWhenReady);
}
use of androidx.media3.common.util.BundleableUtil.fromNullableBundle in project media by androidx.
the class LibraryResult method fromBundle.
/**
* Constructs a new instance from {@code bundle}.
*
* @throws IllegalStateException if {@code expectedType} is non-null and doesn't match the value
* type read from {@code bundle}.
*/
private static LibraryResult<?> fromBundle(Bundle bundle, @Nullable @ValueType Integer expectedType) {
int resultCode = bundle.getInt(keyForField(FIELD_RESULT_CODE), /* defaultValue= */
RESULT_SUCCESS);
long completionTimeMs = bundle.getLong(keyForField(FIELD_COMPLETION_TIME_MS), /* defaultValue= */
SystemClock.elapsedRealtime());
@Nullable MediaLibraryService.LibraryParams params = BundleableUtil.fromNullableBundle(MediaLibraryService.LibraryParams.CREATOR, bundle.getBundle(keyForField(FIELD_PARAMS)));
@ValueType int valueType = bundle.getInt(keyForField(FIELD_VALUE_TYPE));
@Nullable Object value;
switch(valueType) {
case VALUE_TYPE_ITEM:
checkState(expectedType == null || expectedType == VALUE_TYPE_ITEM);
value = BundleableUtil.fromNullableBundle(MediaItem.CREATOR, bundle.getBundle(keyForField(FIELD_VALUE)));
break;
case VALUE_TYPE_ITEM_LIST:
checkState(expectedType == null || expectedType == VALUE_TYPE_ITEM_LIST);
@Nullable IBinder valueRetriever = BundleCompat.getBinder(bundle, keyForField(FIELD_VALUE));
value = valueRetriever == null ? null : BundleableUtil.fromBundleList(MediaItem.CREATOR, BundleListRetriever.getList(valueRetriever));
break;
case VALUE_TYPE_VOID:
case VALUE_TYPE_ERROR:
value = null;
break;
default:
throw new IllegalStateException();
}
return new LibraryResult<>(resultCode, completionTimeMs, params, value, VALUE_TYPE_ITEM_LIST);
}
Aggregations