Search in sources :

Example 6 with BundleableUtil.fromNullableBundle

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);
}
Also used : IBinder(android.os.IBinder) Player(androidx.media3.common.Player) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Nullable(androidx.annotation.Nullable)

Example 7 with BundleableUtil.fromNullableBundle

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);
}
Also used : PositionInfo(androidx.media3.common.Player.PositionInfo)

Example 8 with BundleableUtil.fromNullableBundle

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);
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) Nullable(androidx.annotation.Nullable)

Example 9 with BundleableUtil.fromNullableBundle

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);
}
Also used : LibraryParams(androidx.media3.session.MediaLibraryService.LibraryParams) IBinder(android.os.IBinder) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)8 LibraryParams (androidx.media3.session.MediaLibraryService.LibraryParams)6 Bundle (android.os.Bundle)2 IBinder (android.os.IBinder)2 PositionInfo (androidx.media3.common.Player.PositionInfo)2 PendingIntent (android.app.PendingIntent)1 AudioAttributes (androidx.media3.common.AudioAttributes)1 DeviceInfo (androidx.media3.common.DeviceInfo)1 MediaMetadata (androidx.media3.common.MediaMetadata)1 PlaybackException (androidx.media3.common.PlaybackException)1 PlaybackParameters (androidx.media3.common.PlaybackParameters)1 Player (androidx.media3.common.Player)1 PlaybackSuppressionReason (androidx.media3.common.Player.PlaybackSuppressionReason)1 State (androidx.media3.common.Player.State)1 Timeline (androidx.media3.common.Timeline)1 TrackSelectionParameters (androidx.media3.common.TrackSelectionParameters)1 VideoSize (androidx.media3.common.VideoSize)1 Cue (androidx.media3.common.text.Cue)1