mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Initialise fields used for bundling as String directly
Initialising the fields as Integer and then getting a String on compute time is slow. Instead we directly initialise these fields as String. Improves the time taken in bundling PlayerInfo further to less than 200ms from ~300ms. Also modified a test to improve productive coverage. PiperOrigin-RevId: 500003935 (cherry picked from commit 578f2de48f795ad90aafdad645c62fcdbd686e0a)
This commit is contained in:
parent
2cfd05f125
commit
96eb8968a8
@ -459,44 +459,29 @@ public final class AdPlaybackState implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TIME_US,
|
||||
FIELD_COUNT,
|
||||
FIELD_URIS,
|
||||
FIELD_STATES,
|
||||
FIELD_DURATIONS_US,
|
||||
FIELD_CONTENT_RESUME_OFFSET_US,
|
||||
FIELD_IS_SERVER_SIDE_INSERTED,
|
||||
FIELD_ORIGINAL_COUNT
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TIME_US = 0;
|
||||
private static final int FIELD_COUNT = 1;
|
||||
private static final int FIELD_URIS = 2;
|
||||
private static final int FIELD_STATES = 3;
|
||||
private static final int FIELD_DURATIONS_US = 4;
|
||||
private static final int FIELD_CONTENT_RESUME_OFFSET_US = 5;
|
||||
private static final int FIELD_IS_SERVER_SIDE_INSERTED = 6;
|
||||
private static final int FIELD_ORIGINAL_COUNT = 7;
|
||||
private static final String FIELD_TIME_US = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_COUNT = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_URIS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_STATES = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_DURATIONS_US = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_CONTENT_RESUME_OFFSET_US = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_IS_SERVER_SIDE_INSERTED = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_ORIGINAL_COUNT = Util.intToStringMaxRadix(7);
|
||||
|
||||
// putParcelableArrayList actually supports null elements.
|
||||
@SuppressWarnings("nullness:argument")
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(keyForField(FIELD_TIME_US), timeUs);
|
||||
bundle.putInt(keyForField(FIELD_COUNT), count);
|
||||
bundle.putInt(keyForField(FIELD_ORIGINAL_COUNT), originalCount);
|
||||
bundle.putLong(FIELD_TIME_US, timeUs);
|
||||
bundle.putInt(FIELD_COUNT, count);
|
||||
bundle.putInt(FIELD_ORIGINAL_COUNT, originalCount);
|
||||
bundle.putParcelableArrayList(
|
||||
keyForField(FIELD_URIS), new ArrayList<@NullableType Uri>(Arrays.asList(uris)));
|
||||
bundle.putIntArray(keyForField(FIELD_STATES), states);
|
||||
bundle.putLongArray(keyForField(FIELD_DURATIONS_US), durationsUs);
|
||||
bundle.putLong(keyForField(FIELD_CONTENT_RESUME_OFFSET_US), contentResumeOffsetUs);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_SERVER_SIDE_INSERTED), isServerSideInserted);
|
||||
FIELD_URIS, new ArrayList<@NullableType Uri>(Arrays.asList(uris)));
|
||||
bundle.putIntArray(FIELD_STATES, states);
|
||||
bundle.putLongArray(FIELD_DURATIONS_US, durationsUs);
|
||||
bundle.putLong(FIELD_CONTENT_RESUME_OFFSET_US, contentResumeOffsetUs);
|
||||
bundle.putBoolean(FIELD_IS_SERVER_SIDE_INSERTED, isServerSideInserted);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -506,17 +491,16 @@ public final class AdPlaybackState implements Bundleable {
|
||||
// getParcelableArrayList may have null elements.
|
||||
@SuppressWarnings("nullness:type.argument")
|
||||
private static AdGroup fromBundle(Bundle bundle) {
|
||||
long timeUs = bundle.getLong(keyForField(FIELD_TIME_US));
|
||||
int count = bundle.getInt(keyForField(FIELD_COUNT));
|
||||
int originalCount = bundle.getInt(keyForField(FIELD_ORIGINAL_COUNT));
|
||||
@Nullable
|
||||
ArrayList<@NullableType Uri> uriList = bundle.getParcelableArrayList(keyForField(FIELD_URIS));
|
||||
long timeUs = bundle.getLong(FIELD_TIME_US);
|
||||
int count = bundle.getInt(FIELD_COUNT);
|
||||
int originalCount = bundle.getInt(FIELD_ORIGINAL_COUNT);
|
||||
@Nullable ArrayList<@NullableType Uri> uriList = bundle.getParcelableArrayList(FIELD_URIS);
|
||||
@Nullable
|
||||
@AdState
|
||||
int[] states = bundle.getIntArray(keyForField(FIELD_STATES));
|
||||
@Nullable long[] durationsUs = bundle.getLongArray(keyForField(FIELD_DURATIONS_US));
|
||||
long contentResumeOffsetUs = bundle.getLong(keyForField(FIELD_CONTENT_RESUME_OFFSET_US));
|
||||
boolean isServerSideInserted = bundle.getBoolean(keyForField(FIELD_IS_SERVER_SIDE_INSERTED));
|
||||
int[] states = bundle.getIntArray(FIELD_STATES);
|
||||
@Nullable long[] durationsUs = bundle.getLongArray(FIELD_DURATIONS_US);
|
||||
long contentResumeOffsetUs = bundle.getLong(FIELD_CONTENT_RESUME_OFFSET_US);
|
||||
boolean isServerSideInserted = bundle.getBoolean(FIELD_IS_SERVER_SIDE_INSERTED);
|
||||
return new AdGroup(
|
||||
timeUs,
|
||||
count,
|
||||
@ -527,10 +511,6 @@ public final class AdPlaybackState implements Bundleable {
|
||||
contentResumeOffsetUs,
|
||||
isServerSideInserted);
|
||||
}
|
||||
|
||||
private static String keyForField(@AdGroup.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1121,21 +1101,10 @@ public final class AdPlaybackState implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_AD_GROUPS,
|
||||
FIELD_AD_RESUME_POSITION_US,
|
||||
FIELD_CONTENT_DURATION_US,
|
||||
FIELD_REMOVED_AD_GROUP_COUNT
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_AD_GROUPS = 1;
|
||||
private static final int FIELD_AD_RESUME_POSITION_US = 2;
|
||||
private static final int FIELD_CONTENT_DURATION_US = 3;
|
||||
private static final int FIELD_REMOVED_AD_GROUP_COUNT = 4;
|
||||
private static final String FIELD_AD_GROUPS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_AD_RESUME_POSITION_US = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_CONTENT_DURATION_US = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_REMOVED_AD_GROUP_COUNT = Util.intToStringMaxRadix(4);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -1152,16 +1121,16 @@ public final class AdPlaybackState implements Bundleable {
|
||||
adGroupBundleList.add(adGroup.toBundle());
|
||||
}
|
||||
if (!adGroupBundleList.isEmpty()) {
|
||||
bundle.putParcelableArrayList(keyForField(FIELD_AD_GROUPS), adGroupBundleList);
|
||||
bundle.putParcelableArrayList(FIELD_AD_GROUPS, adGroupBundleList);
|
||||
}
|
||||
if (adResumePositionUs != NONE.adResumePositionUs) {
|
||||
bundle.putLong(keyForField(FIELD_AD_RESUME_POSITION_US), adResumePositionUs);
|
||||
bundle.putLong(FIELD_AD_RESUME_POSITION_US, adResumePositionUs);
|
||||
}
|
||||
if (contentDurationUs != NONE.contentDurationUs) {
|
||||
bundle.putLong(keyForField(FIELD_CONTENT_DURATION_US), contentDurationUs);
|
||||
bundle.putLong(FIELD_CONTENT_DURATION_US, contentDurationUs);
|
||||
}
|
||||
if (removedAdGroupCount != NONE.removedAdGroupCount) {
|
||||
bundle.putInt(keyForField(FIELD_REMOVED_AD_GROUP_COUNT), removedAdGroupCount);
|
||||
bundle.putInt(FIELD_REMOVED_AD_GROUP_COUNT, removedAdGroupCount);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -1174,9 +1143,7 @@ public final class AdPlaybackState implements Bundleable {
|
||||
public static final Bundleable.Creator<AdPlaybackState> CREATOR = AdPlaybackState::fromBundle;
|
||||
|
||||
private static AdPlaybackState fromBundle(Bundle bundle) {
|
||||
@Nullable
|
||||
ArrayList<Bundle> adGroupBundleList =
|
||||
bundle.getParcelableArrayList(keyForField(FIELD_AD_GROUPS));
|
||||
@Nullable ArrayList<Bundle> adGroupBundleList = bundle.getParcelableArrayList(FIELD_AD_GROUPS);
|
||||
@Nullable AdGroup[] adGroups;
|
||||
if (adGroupBundleList == null) {
|
||||
adGroups = new AdGroup[0];
|
||||
@ -1187,23 +1154,15 @@ public final class AdPlaybackState implements Bundleable {
|
||||
}
|
||||
}
|
||||
long adResumePositionUs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_AD_RESUME_POSITION_US), /* defaultValue= */ NONE.adResumePositionUs);
|
||||
bundle.getLong(FIELD_AD_RESUME_POSITION_US, /* defaultValue= */ NONE.adResumePositionUs);
|
||||
long contentDurationUs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_CONTENT_DURATION_US), /* defaultValue= */ NONE.contentDurationUs);
|
||||
bundle.getLong(FIELD_CONTENT_DURATION_US, /* defaultValue= */ NONE.contentDurationUs);
|
||||
int removedAdGroupCount =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_REMOVED_AD_GROUP_COUNT),
|
||||
/* defaultValue= */ NONE.removedAdGroupCount);
|
||||
bundle.getInt(FIELD_REMOVED_AD_GROUP_COUNT, /* defaultValue= */ NONE.removedAdGroupCount);
|
||||
return new AdPlaybackState(
|
||||
/* adsId= */ null, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
private static AdGroup[] createEmptyAdGroups(long[] adGroupTimesUs) {
|
||||
AdGroup[] adGroups = new AdGroup[adGroupTimesUs.length];
|
||||
for (int i = 0; i < adGroups.length; i++) {
|
||||
|
@ -15,20 +15,13 @@
|
||||
*/
|
||||
package androidx.media3.common;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.DoNotInline;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Attributes for audio playback, which configure the underlying platform {@link
|
||||
@ -205,33 +198,21 @@ public final class AudioAttributes implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_CONTENT_TYPE,
|
||||
FIELD_FLAGS,
|
||||
FIELD_USAGE,
|
||||
FIELD_ALLOWED_CAPTURE_POLICY,
|
||||
FIELD_SPATIALIZATION_BEHAVIOR
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_CONTENT_TYPE = 0;
|
||||
private static final int FIELD_FLAGS = 1;
|
||||
private static final int FIELD_USAGE = 2;
|
||||
private static final int FIELD_ALLOWED_CAPTURE_POLICY = 3;
|
||||
private static final int FIELD_SPATIALIZATION_BEHAVIOR = 4;
|
||||
private static final String FIELD_CONTENT_TYPE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_FLAGS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_USAGE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_ALLOWED_CAPTURE_POLICY = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_SPATIALIZATION_BEHAVIOR = Util.intToStringMaxRadix(4);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_CONTENT_TYPE), contentType);
|
||||
bundle.putInt(keyForField(FIELD_FLAGS), flags);
|
||||
bundle.putInt(keyForField(FIELD_USAGE), usage);
|
||||
bundle.putInt(keyForField(FIELD_ALLOWED_CAPTURE_POLICY), allowedCapturePolicy);
|
||||
bundle.putInt(keyForField(FIELD_SPATIALIZATION_BEHAVIOR), spatializationBehavior);
|
||||
bundle.putInt(FIELD_CONTENT_TYPE, contentType);
|
||||
bundle.putInt(FIELD_FLAGS, flags);
|
||||
bundle.putInt(FIELD_USAGE, usage);
|
||||
bundle.putInt(FIELD_ALLOWED_CAPTURE_POLICY, allowedCapturePolicy);
|
||||
bundle.putInt(FIELD_SPATIALIZATION_BEHAVIOR, spatializationBehavior);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -240,29 +221,24 @@ public final class AudioAttributes implements Bundleable {
|
||||
public static final Creator<AudioAttributes> CREATOR =
|
||||
bundle -> {
|
||||
Builder builder = new Builder();
|
||||
if (bundle.containsKey(keyForField(FIELD_CONTENT_TYPE))) {
|
||||
builder.setContentType(bundle.getInt(keyForField(FIELD_CONTENT_TYPE)));
|
||||
if (bundle.containsKey(FIELD_CONTENT_TYPE)) {
|
||||
builder.setContentType(bundle.getInt(FIELD_CONTENT_TYPE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_FLAGS))) {
|
||||
builder.setFlags(bundle.getInt(keyForField(FIELD_FLAGS)));
|
||||
if (bundle.containsKey(FIELD_FLAGS)) {
|
||||
builder.setFlags(bundle.getInt(FIELD_FLAGS));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_USAGE))) {
|
||||
builder.setUsage(bundle.getInt(keyForField(FIELD_USAGE)));
|
||||
if (bundle.containsKey(FIELD_USAGE)) {
|
||||
builder.setUsage(bundle.getInt(FIELD_USAGE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_ALLOWED_CAPTURE_POLICY))) {
|
||||
builder.setAllowedCapturePolicy(bundle.getInt(keyForField(FIELD_ALLOWED_CAPTURE_POLICY)));
|
||||
if (bundle.containsKey(FIELD_ALLOWED_CAPTURE_POLICY)) {
|
||||
builder.setAllowedCapturePolicy(bundle.getInt(FIELD_ALLOWED_CAPTURE_POLICY));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_SPATIALIZATION_BEHAVIOR))) {
|
||||
builder.setSpatializationBehavior(
|
||||
bundle.getInt(keyForField(FIELD_SPATIALIZATION_BEHAVIOR)));
|
||||
if (bundle.containsKey(FIELD_SPATIALIZATION_BEHAVIOR)) {
|
||||
builder.setSpatializationBehavior(bundle.getInt(FIELD_SPATIALIZATION_BEHAVIOR));
|
||||
}
|
||||
return builder.build();
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
@RequiresApi(29)
|
||||
private static final class Api29 {
|
||||
@DoNotInline
|
||||
|
@ -15,16 +15,10 @@
|
||||
*/
|
||||
package androidx.media3.common;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.util.Arrays;
|
||||
import org.checkerframework.dataflow.qual.Pure;
|
||||
|
||||
@ -183,41 +177,26 @@ public final class ColorInfo implements Bundleable {
|
||||
|
||||
// Bundleable implementation
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_COLOR_SPACE,
|
||||
FIELD_COLOR_RANGE,
|
||||
FIELD_COLOR_TRANSFER,
|
||||
FIELD_HDR_STATIC_INFO,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_COLOR_SPACE = 0;
|
||||
private static final int FIELD_COLOR_RANGE = 1;
|
||||
private static final int FIELD_COLOR_TRANSFER = 2;
|
||||
private static final int FIELD_HDR_STATIC_INFO = 3;
|
||||
private static final String FIELD_COLOR_SPACE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_COLOR_RANGE = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_COLOR_TRANSFER = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_HDR_STATIC_INFO = Util.intToStringMaxRadix(3);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_COLOR_SPACE), colorSpace);
|
||||
bundle.putInt(keyForField(FIELD_COLOR_RANGE), colorRange);
|
||||
bundle.putInt(keyForField(FIELD_COLOR_TRANSFER), colorTransfer);
|
||||
bundle.putByteArray(keyForField(FIELD_HDR_STATIC_INFO), hdrStaticInfo);
|
||||
bundle.putInt(FIELD_COLOR_SPACE, colorSpace);
|
||||
bundle.putInt(FIELD_COLOR_RANGE, colorRange);
|
||||
bundle.putInt(FIELD_COLOR_TRANSFER, colorTransfer);
|
||||
bundle.putByteArray(FIELD_HDR_STATIC_INFO, hdrStaticInfo);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public static final Creator<ColorInfo> CREATOR =
|
||||
bundle ->
|
||||
new ColorInfo(
|
||||
bundle.getInt(keyForField(FIELD_COLOR_SPACE), Format.NO_VALUE),
|
||||
bundle.getInt(keyForField(FIELD_COLOR_RANGE), Format.NO_VALUE),
|
||||
bundle.getInt(keyForField(FIELD_COLOR_TRANSFER), Format.NO_VALUE),
|
||||
bundle.getByteArray(keyForField(FIELD_HDR_STATIC_INFO)));
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
bundle.getInt(FIELD_COLOR_SPACE, Format.NO_VALUE),
|
||||
bundle.getInt(FIELD_COLOR_RANGE, Format.NO_VALUE),
|
||||
bundle.getInt(FIELD_COLOR_TRANSFER, Format.NO_VALUE),
|
||||
bundle.getByteArray(FIELD_HDR_STATIC_INFO));
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -87,23 +88,17 @@ public final class DeviceInfo implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_PLAYBACK_TYPE, FIELD_MIN_VOLUME, FIELD_MAX_VOLUME})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_PLAYBACK_TYPE = 0;
|
||||
private static final int FIELD_MIN_VOLUME = 1;
|
||||
private static final int FIELD_MAX_VOLUME = 2;
|
||||
private static final String FIELD_PLAYBACK_TYPE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_MIN_VOLUME = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_MAX_VOLUME = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_PLAYBACK_TYPE), playbackType);
|
||||
bundle.putInt(keyForField(FIELD_MIN_VOLUME), minVolume);
|
||||
bundle.putInt(keyForField(FIELD_MAX_VOLUME), maxVolume);
|
||||
bundle.putInt(FIELD_PLAYBACK_TYPE, playbackType);
|
||||
bundle.putInt(FIELD_MIN_VOLUME, minVolume);
|
||||
bundle.putInt(FIELD_MAX_VOLUME, maxVolume);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -112,14 +107,9 @@ public final class DeviceInfo implements Bundleable {
|
||||
public static final Creator<DeviceInfo> CREATOR =
|
||||
bundle -> {
|
||||
int playbackType =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PLAYBACK_TYPE), /* defaultValue= */ PLAYBACK_TYPE_LOCAL);
|
||||
int minVolume = bundle.getInt(keyForField(FIELD_MIN_VOLUME), /* defaultValue= */ 0);
|
||||
int maxVolume = bundle.getInt(keyForField(FIELD_MAX_VOLUME), /* defaultValue= */ 0);
|
||||
bundle.getInt(FIELD_PLAYBACK_TYPE, /* defaultValue= */ PLAYBACK_TYPE_LOCAL);
|
||||
int minVolume = bundle.getInt(FIELD_MIN_VOLUME, /* defaultValue= */ 0);
|
||||
int maxVolume = bundle.getInt(FIELD_MAX_VOLUME, /* defaultValue= */ 0);
|
||||
return new DeviceInfo(playbackType, minVolume, maxVolume);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -15,20 +15,13 @@
|
||||
*/
|
||||
package androidx.media3.common;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -1476,73 +1469,37 @@ public final class Format implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_ID,
|
||||
FIELD_LABEL,
|
||||
FIELD_LANGUAGE,
|
||||
FIELD_SELECTION_FLAGS,
|
||||
FIELD_ROLE_FLAGS,
|
||||
FIELD_AVERAGE_BITRATE,
|
||||
FIELD_PEAK_BITRATE,
|
||||
FIELD_CODECS,
|
||||
FIELD_METADATA,
|
||||
FIELD_CONTAINER_MIME_TYPE,
|
||||
FIELD_SAMPLE_MIME_TYPE,
|
||||
FIELD_MAX_INPUT_SIZE,
|
||||
FIELD_INITIALIZATION_DATA,
|
||||
FIELD_DRM_INIT_DATA,
|
||||
FIELD_SUBSAMPLE_OFFSET_US,
|
||||
FIELD_WIDTH,
|
||||
FIELD_HEIGHT,
|
||||
FIELD_FRAME_RATE,
|
||||
FIELD_ROTATION_DEGREES,
|
||||
FIELD_PIXEL_WIDTH_HEIGHT_RATIO,
|
||||
FIELD_PROJECTION_DATA,
|
||||
FIELD_STEREO_MODE,
|
||||
FIELD_COLOR_INFO,
|
||||
FIELD_CHANNEL_COUNT,
|
||||
FIELD_SAMPLE_RATE,
|
||||
FIELD_PCM_ENCODING,
|
||||
FIELD_ENCODER_DELAY,
|
||||
FIELD_ENCODER_PADDING,
|
||||
FIELD_ACCESSIBILITY_CHANNEL,
|
||||
FIELD_CRYPTO_TYPE,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_ID = 0;
|
||||
private static final int FIELD_LABEL = 1;
|
||||
private static final int FIELD_LANGUAGE = 2;
|
||||
private static final int FIELD_SELECTION_FLAGS = 3;
|
||||
private static final int FIELD_ROLE_FLAGS = 4;
|
||||
private static final int FIELD_AVERAGE_BITRATE = 5;
|
||||
private static final int FIELD_PEAK_BITRATE = 6;
|
||||
private static final int FIELD_CODECS = 7;
|
||||
private static final int FIELD_METADATA = 8;
|
||||
private static final int FIELD_CONTAINER_MIME_TYPE = 9;
|
||||
private static final int FIELD_SAMPLE_MIME_TYPE = 10;
|
||||
private static final int FIELD_MAX_INPUT_SIZE = 11;
|
||||
private static final int FIELD_INITIALIZATION_DATA = 12;
|
||||
private static final int FIELD_DRM_INIT_DATA = 13;
|
||||
private static final int FIELD_SUBSAMPLE_OFFSET_US = 14;
|
||||
private static final int FIELD_WIDTH = 15;
|
||||
private static final int FIELD_HEIGHT = 16;
|
||||
private static final int FIELD_FRAME_RATE = 17;
|
||||
private static final int FIELD_ROTATION_DEGREES = 18;
|
||||
private static final int FIELD_PIXEL_WIDTH_HEIGHT_RATIO = 19;
|
||||
private static final int FIELD_PROJECTION_DATA = 20;
|
||||
private static final int FIELD_STEREO_MODE = 21;
|
||||
private static final int FIELD_COLOR_INFO = 22;
|
||||
private static final int FIELD_CHANNEL_COUNT = 23;
|
||||
private static final int FIELD_SAMPLE_RATE = 24;
|
||||
private static final int FIELD_PCM_ENCODING = 25;
|
||||
private static final int FIELD_ENCODER_DELAY = 26;
|
||||
private static final int FIELD_ENCODER_PADDING = 27;
|
||||
private static final int FIELD_ACCESSIBILITY_CHANNEL = 28;
|
||||
private static final int FIELD_CRYPTO_TYPE = 29;
|
||||
private static final String FIELD_ID = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_LABEL = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_LANGUAGE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_SELECTION_FLAGS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_ROLE_FLAGS = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_AVERAGE_BITRATE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_PEAK_BITRATE = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_CODECS = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_METADATA = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_CONTAINER_MIME_TYPE = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_SAMPLE_MIME_TYPE = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_MAX_INPUT_SIZE = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_INITIALIZATION_DATA = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_DRM_INIT_DATA = Util.intToStringMaxRadix(13);
|
||||
private static final String FIELD_SUBSAMPLE_OFFSET_US = Util.intToStringMaxRadix(14);
|
||||
private static final String FIELD_WIDTH = Util.intToStringMaxRadix(15);
|
||||
private static final String FIELD_HEIGHT = Util.intToStringMaxRadix(16);
|
||||
private static final String FIELD_FRAME_RATE = Util.intToStringMaxRadix(17);
|
||||
private static final String FIELD_ROTATION_DEGREES = Util.intToStringMaxRadix(18);
|
||||
private static final String FIELD_PIXEL_WIDTH_HEIGHT_RATIO = Util.intToStringMaxRadix(19);
|
||||
private static final String FIELD_PROJECTION_DATA = Util.intToStringMaxRadix(20);
|
||||
private static final String FIELD_STEREO_MODE = Util.intToStringMaxRadix(21);
|
||||
private static final String FIELD_COLOR_INFO = Util.intToStringMaxRadix(22);
|
||||
private static final String FIELD_CHANNEL_COUNT = Util.intToStringMaxRadix(23);
|
||||
private static final String FIELD_SAMPLE_RATE = Util.intToStringMaxRadix(24);
|
||||
private static final String FIELD_PCM_ENCODING = Util.intToStringMaxRadix(25);
|
||||
private static final String FIELD_ENCODER_DELAY = Util.intToStringMaxRadix(26);
|
||||
private static final String FIELD_ENCODER_PADDING = Util.intToStringMaxRadix(27);
|
||||
private static final String FIELD_ACCESSIBILITY_CHANNEL = Util.intToStringMaxRadix(28);
|
||||
private static final String FIELD_CRYPTO_TYPE = Util.intToStringMaxRadix(29);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
@ -1557,51 +1514,51 @@ public final class Format implements Bundleable {
|
||||
@UnstableApi
|
||||
public Bundle toBundle(boolean excludeMetadata) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(keyForField(FIELD_ID), id);
|
||||
bundle.putString(keyForField(FIELD_LABEL), label);
|
||||
bundle.putString(keyForField(FIELD_LANGUAGE), language);
|
||||
bundle.putInt(keyForField(FIELD_SELECTION_FLAGS), selectionFlags);
|
||||
bundle.putInt(keyForField(FIELD_ROLE_FLAGS), roleFlags);
|
||||
bundle.putInt(keyForField(FIELD_AVERAGE_BITRATE), averageBitrate);
|
||||
bundle.putInt(keyForField(FIELD_PEAK_BITRATE), peakBitrate);
|
||||
bundle.putString(keyForField(FIELD_CODECS), codecs);
|
||||
bundle.putString(FIELD_ID, id);
|
||||
bundle.putString(FIELD_LABEL, label);
|
||||
bundle.putString(FIELD_LANGUAGE, language);
|
||||
bundle.putInt(FIELD_SELECTION_FLAGS, selectionFlags);
|
||||
bundle.putInt(FIELD_ROLE_FLAGS, roleFlags);
|
||||
bundle.putInt(FIELD_AVERAGE_BITRATE, averageBitrate);
|
||||
bundle.putInt(FIELD_PEAK_BITRATE, peakBitrate);
|
||||
bundle.putString(FIELD_CODECS, codecs);
|
||||
if (!excludeMetadata) {
|
||||
// TODO (internal ref: b/239701618)
|
||||
bundle.putParcelable(keyForField(FIELD_METADATA), metadata);
|
||||
bundle.putParcelable(FIELD_METADATA, metadata);
|
||||
}
|
||||
// Container specific.
|
||||
bundle.putString(keyForField(FIELD_CONTAINER_MIME_TYPE), containerMimeType);
|
||||
bundle.putString(FIELD_CONTAINER_MIME_TYPE, containerMimeType);
|
||||
// Sample specific.
|
||||
bundle.putString(keyForField(FIELD_SAMPLE_MIME_TYPE), sampleMimeType);
|
||||
bundle.putInt(keyForField(FIELD_MAX_INPUT_SIZE), maxInputSize);
|
||||
bundle.putString(FIELD_SAMPLE_MIME_TYPE, sampleMimeType);
|
||||
bundle.putInt(FIELD_MAX_INPUT_SIZE, maxInputSize);
|
||||
for (int i = 0; i < initializationData.size(); i++) {
|
||||
bundle.putByteArray(keyForInitializationData(i), initializationData.get(i));
|
||||
}
|
||||
// DrmInitData doesn't need to be Bundleable as it's only used in the playing process to
|
||||
// initialize the decoder.
|
||||
bundle.putParcelable(keyForField(FIELD_DRM_INIT_DATA), drmInitData);
|
||||
bundle.putLong(keyForField(FIELD_SUBSAMPLE_OFFSET_US), subsampleOffsetUs);
|
||||
bundle.putParcelable(FIELD_DRM_INIT_DATA, drmInitData);
|
||||
bundle.putLong(FIELD_SUBSAMPLE_OFFSET_US, subsampleOffsetUs);
|
||||
// Video specific.
|
||||
bundle.putInt(keyForField(FIELD_WIDTH), width);
|
||||
bundle.putInt(keyForField(FIELD_HEIGHT), height);
|
||||
bundle.putFloat(keyForField(FIELD_FRAME_RATE), frameRate);
|
||||
bundle.putInt(keyForField(FIELD_ROTATION_DEGREES), rotationDegrees);
|
||||
bundle.putFloat(keyForField(FIELD_PIXEL_WIDTH_HEIGHT_RATIO), pixelWidthHeightRatio);
|
||||
bundle.putByteArray(keyForField(FIELD_PROJECTION_DATA), projectionData);
|
||||
bundle.putInt(keyForField(FIELD_STEREO_MODE), stereoMode);
|
||||
bundle.putInt(FIELD_WIDTH, width);
|
||||
bundle.putInt(FIELD_HEIGHT, height);
|
||||
bundle.putFloat(FIELD_FRAME_RATE, frameRate);
|
||||
bundle.putInt(FIELD_ROTATION_DEGREES, rotationDegrees);
|
||||
bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio);
|
||||
bundle.putByteArray(FIELD_PROJECTION_DATA, projectionData);
|
||||
bundle.putInt(FIELD_STEREO_MODE, stereoMode);
|
||||
if (colorInfo != null) {
|
||||
bundle.putBundle(keyForField(FIELD_COLOR_INFO), colorInfo.toBundle());
|
||||
bundle.putBundle(FIELD_COLOR_INFO, colorInfo.toBundle());
|
||||
}
|
||||
// Audio specific.
|
||||
bundle.putInt(keyForField(FIELD_CHANNEL_COUNT), channelCount);
|
||||
bundle.putInt(keyForField(FIELD_SAMPLE_RATE), sampleRate);
|
||||
bundle.putInt(keyForField(FIELD_PCM_ENCODING), pcmEncoding);
|
||||
bundle.putInt(keyForField(FIELD_ENCODER_DELAY), encoderDelay);
|
||||
bundle.putInt(keyForField(FIELD_ENCODER_PADDING), encoderPadding);
|
||||
bundle.putInt(FIELD_CHANNEL_COUNT, channelCount);
|
||||
bundle.putInt(FIELD_SAMPLE_RATE, sampleRate);
|
||||
bundle.putInt(FIELD_PCM_ENCODING, pcmEncoding);
|
||||
bundle.putInt(FIELD_ENCODER_DELAY, encoderDelay);
|
||||
bundle.putInt(FIELD_ENCODER_PADDING, encoderPadding);
|
||||
// Text specific.
|
||||
bundle.putInt(keyForField(FIELD_ACCESSIBILITY_CHANNEL), accessibilityChannel);
|
||||
bundle.putInt(FIELD_ACCESSIBILITY_CHANNEL, accessibilityChannel);
|
||||
// Source specific.
|
||||
bundle.putInt(keyForField(FIELD_CRYPTO_TYPE), cryptoType);
|
||||
bundle.putInt(FIELD_CRYPTO_TYPE, cryptoType);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -1612,28 +1569,22 @@ public final class Format implements Bundleable {
|
||||
Builder builder = new Builder();
|
||||
BundleableUtil.ensureClassLoader(bundle);
|
||||
builder
|
||||
.setId(defaultIfNull(bundle.getString(keyForField(FIELD_ID)), DEFAULT.id))
|
||||
.setLabel(defaultIfNull(bundle.getString(keyForField(FIELD_LABEL)), DEFAULT.label))
|
||||
.setLanguage(defaultIfNull(bundle.getString(keyForField(FIELD_LANGUAGE)), DEFAULT.language))
|
||||
.setSelectionFlags(
|
||||
bundle.getInt(keyForField(FIELD_SELECTION_FLAGS), DEFAULT.selectionFlags))
|
||||
.setRoleFlags(bundle.getInt(keyForField(FIELD_ROLE_FLAGS), DEFAULT.roleFlags))
|
||||
.setAverageBitrate(
|
||||
bundle.getInt(keyForField(FIELD_AVERAGE_BITRATE), DEFAULT.averageBitrate))
|
||||
.setPeakBitrate(bundle.getInt(keyForField(FIELD_PEAK_BITRATE), DEFAULT.peakBitrate))
|
||||
.setCodecs(defaultIfNull(bundle.getString(keyForField(FIELD_CODECS)), DEFAULT.codecs))
|
||||
.setMetadata(
|
||||
defaultIfNull(bundle.getParcelable(keyForField(FIELD_METADATA)), DEFAULT.metadata))
|
||||
.setId(defaultIfNull(bundle.getString(FIELD_ID), DEFAULT.id))
|
||||
.setLabel(defaultIfNull(bundle.getString(FIELD_LABEL), DEFAULT.label))
|
||||
.setLanguage(defaultIfNull(bundle.getString(FIELD_LANGUAGE), DEFAULT.language))
|
||||
.setSelectionFlags(bundle.getInt(FIELD_SELECTION_FLAGS, DEFAULT.selectionFlags))
|
||||
.setRoleFlags(bundle.getInt(FIELD_ROLE_FLAGS, DEFAULT.roleFlags))
|
||||
.setAverageBitrate(bundle.getInt(FIELD_AVERAGE_BITRATE, DEFAULT.averageBitrate))
|
||||
.setPeakBitrate(bundle.getInt(FIELD_PEAK_BITRATE, DEFAULT.peakBitrate))
|
||||
.setCodecs(defaultIfNull(bundle.getString(FIELD_CODECS), DEFAULT.codecs))
|
||||
.setMetadata(defaultIfNull(bundle.getParcelable(FIELD_METADATA), DEFAULT.metadata))
|
||||
// Container specific.
|
||||
.setContainerMimeType(
|
||||
defaultIfNull(
|
||||
bundle.getString(keyForField(FIELD_CONTAINER_MIME_TYPE)),
|
||||
DEFAULT.containerMimeType))
|
||||
defaultIfNull(bundle.getString(FIELD_CONTAINER_MIME_TYPE), DEFAULT.containerMimeType))
|
||||
// Sample specific.
|
||||
.setSampleMimeType(
|
||||
defaultIfNull(
|
||||
bundle.getString(keyForField(FIELD_SAMPLE_MIME_TYPE)), DEFAULT.sampleMimeType))
|
||||
.setMaxInputSize(bundle.getInt(keyForField(FIELD_MAX_INPUT_SIZE), DEFAULT.maxInputSize));
|
||||
defaultIfNull(bundle.getString(FIELD_SAMPLE_MIME_TYPE), DEFAULT.sampleMimeType))
|
||||
.setMaxInputSize(bundle.getInt(FIELD_MAX_INPUT_SIZE, DEFAULT.maxInputSize));
|
||||
|
||||
List<byte[]> initializationData = new ArrayList<>();
|
||||
for (int i = 0; ; i++) {
|
||||
@ -1645,47 +1596,39 @@ public final class Format implements Bundleable {
|
||||
}
|
||||
builder
|
||||
.setInitializationData(initializationData)
|
||||
.setDrmInitData(bundle.getParcelable(keyForField(FIELD_DRM_INIT_DATA)))
|
||||
.setSubsampleOffsetUs(
|
||||
bundle.getLong(keyForField(FIELD_SUBSAMPLE_OFFSET_US), DEFAULT.subsampleOffsetUs))
|
||||
.setDrmInitData(bundle.getParcelable(FIELD_DRM_INIT_DATA))
|
||||
.setSubsampleOffsetUs(bundle.getLong(FIELD_SUBSAMPLE_OFFSET_US, DEFAULT.subsampleOffsetUs))
|
||||
// Video specific.
|
||||
.setWidth(bundle.getInt(keyForField(FIELD_WIDTH), DEFAULT.width))
|
||||
.setHeight(bundle.getInt(keyForField(FIELD_HEIGHT), DEFAULT.height))
|
||||
.setFrameRate(bundle.getFloat(keyForField(FIELD_FRAME_RATE), DEFAULT.frameRate))
|
||||
.setRotationDegrees(
|
||||
bundle.getInt(keyForField(FIELD_ROTATION_DEGREES), DEFAULT.rotationDegrees))
|
||||
.setWidth(bundle.getInt(FIELD_WIDTH, DEFAULT.width))
|
||||
.setHeight(bundle.getInt(FIELD_HEIGHT, DEFAULT.height))
|
||||
.setFrameRate(bundle.getFloat(FIELD_FRAME_RATE, DEFAULT.frameRate))
|
||||
.setRotationDegrees(bundle.getInt(FIELD_ROTATION_DEGREES, DEFAULT.rotationDegrees))
|
||||
.setPixelWidthHeightRatio(
|
||||
bundle.getFloat(
|
||||
keyForField(FIELD_PIXEL_WIDTH_HEIGHT_RATIO), DEFAULT.pixelWidthHeightRatio))
|
||||
.setProjectionData(bundle.getByteArray(keyForField(FIELD_PROJECTION_DATA)))
|
||||
.setStereoMode(bundle.getInt(keyForField(FIELD_STEREO_MODE), DEFAULT.stereoMode));
|
||||
Bundle colorInfoBundle = bundle.getBundle(keyForField(FIELD_COLOR_INFO));
|
||||
bundle.getFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, DEFAULT.pixelWidthHeightRatio))
|
||||
.setProjectionData(bundle.getByteArray(FIELD_PROJECTION_DATA))
|
||||
.setStereoMode(bundle.getInt(FIELD_STEREO_MODE, DEFAULT.stereoMode));
|
||||
Bundle colorInfoBundle = bundle.getBundle(FIELD_COLOR_INFO);
|
||||
if (colorInfoBundle != null) {
|
||||
builder.setColorInfo(ColorInfo.CREATOR.fromBundle(colorInfoBundle));
|
||||
}
|
||||
// Audio specific.
|
||||
builder
|
||||
.setChannelCount(bundle.getInt(keyForField(FIELD_CHANNEL_COUNT), DEFAULT.channelCount))
|
||||
.setSampleRate(bundle.getInt(keyForField(FIELD_SAMPLE_RATE), DEFAULT.sampleRate))
|
||||
.setPcmEncoding(bundle.getInt(keyForField(FIELD_PCM_ENCODING), DEFAULT.pcmEncoding))
|
||||
.setEncoderDelay(bundle.getInt(keyForField(FIELD_ENCODER_DELAY), DEFAULT.encoderDelay))
|
||||
.setEncoderPadding(
|
||||
bundle.getInt(keyForField(FIELD_ENCODER_PADDING), DEFAULT.encoderPadding))
|
||||
.setChannelCount(bundle.getInt(FIELD_CHANNEL_COUNT, DEFAULT.channelCount))
|
||||
.setSampleRate(bundle.getInt(FIELD_SAMPLE_RATE, DEFAULT.sampleRate))
|
||||
.setPcmEncoding(bundle.getInt(FIELD_PCM_ENCODING, DEFAULT.pcmEncoding))
|
||||
.setEncoderDelay(bundle.getInt(FIELD_ENCODER_DELAY, DEFAULT.encoderDelay))
|
||||
.setEncoderPadding(bundle.getInt(FIELD_ENCODER_PADDING, DEFAULT.encoderPadding))
|
||||
// Text specific.
|
||||
.setAccessibilityChannel(
|
||||
bundle.getInt(keyForField(FIELD_ACCESSIBILITY_CHANNEL), DEFAULT.accessibilityChannel))
|
||||
bundle.getInt(FIELD_ACCESSIBILITY_CHANNEL, DEFAULT.accessibilityChannel))
|
||||
// Source specific.
|
||||
.setCryptoType(bundle.getInt(keyForField(FIELD_CRYPTO_TYPE), DEFAULT.cryptoType));
|
||||
.setCryptoType(bundle.getInt(FIELD_CRYPTO_TYPE, DEFAULT.cryptoType));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
private static String keyForInitializationData(int initialisationDataIndex) {
|
||||
return keyForField(FIELD_INITIALIZATION_DATA)
|
||||
return FIELD_INITIALIZATION_DATA
|
||||
+ "_"
|
||||
+ Integer.toString(initialisationDataIndex, Character.MAX_RADIX);
|
||||
}
|
||||
|
@ -16,17 +16,12 @@
|
||||
package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* A rating expressed as "heart" or "no heart". It can be used to indicate whether the content is a
|
||||
@ -81,22 +76,16 @@ public final class HeartRating extends Rating {
|
||||
|
||||
private static final @RatingType int TYPE = RATING_TYPE_HEART;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RATING_TYPE, FIELD_RATED, FIELD_IS_HEART})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_RATED = 1;
|
||||
private static final int FIELD_IS_HEART = 2;
|
||||
private static final String FIELD_RATED = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_IS_HEART = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RATING_TYPE), TYPE);
|
||||
bundle.putBoolean(keyForField(FIELD_RATED), rated);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_HEART), isHeart);
|
||||
bundle.putInt(FIELD_RATING_TYPE, TYPE);
|
||||
bundle.putBoolean(FIELD_RATED, rated);
|
||||
bundle.putBoolean(FIELD_IS_HEART, isHeart);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -104,16 +93,10 @@ public final class HeartRating extends Rating {
|
||||
@UnstableApi public static final Creator<HeartRating> CREATOR = HeartRating::fromBundle;
|
||||
|
||||
private static HeartRating fromBundle(Bundle bundle) {
|
||||
checkArgument(
|
||||
bundle.getInt(keyForField(FIELD_RATING_TYPE), /* defaultValue= */ RATING_TYPE_UNSET)
|
||||
== TYPE);
|
||||
boolean isRated = bundle.getBoolean(keyForField(FIELD_RATED), /* defaultValue= */ false);
|
||||
checkArgument(bundle.getInt(FIELD_RATING_TYPE, /* defaultValue= */ RATING_TYPE_UNSET) == TYPE);
|
||||
boolean isRated = bundle.getBoolean(FIELD_RATED, /* defaultValue= */ false);
|
||||
return isRated
|
||||
? new HeartRating(bundle.getBoolean(keyForField(FIELD_IS_HEART), /* defaultValue= */ false))
|
||||
? new HeartRating(bundle.getBoolean(FIELD_IS_HEART, /* defaultValue= */ false))
|
||||
: new HeartRating();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,9 @@ package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Assertions.checkState;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
@ -31,10 +29,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import com.google.errorprone.annotations.InlineMe;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -1304,42 +1298,30 @@ public final class MediaItem implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TARGET_OFFSET_MS,
|
||||
FIELD_MIN_OFFSET_MS,
|
||||
FIELD_MAX_OFFSET_MS,
|
||||
FIELD_MIN_PLAYBACK_SPEED,
|
||||
FIELD_MAX_PLAYBACK_SPEED
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TARGET_OFFSET_MS = 0;
|
||||
private static final int FIELD_MIN_OFFSET_MS = 1;
|
||||
private static final int FIELD_MAX_OFFSET_MS = 2;
|
||||
private static final int FIELD_MIN_PLAYBACK_SPEED = 3;
|
||||
private static final int FIELD_MAX_PLAYBACK_SPEED = 4;
|
||||
private static final String FIELD_TARGET_OFFSET_MS = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_MIN_OFFSET_MS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_MAX_OFFSET_MS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_MIN_PLAYBACK_SPEED = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_MAX_PLAYBACK_SPEED = Util.intToStringMaxRadix(4);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (targetOffsetMs != UNSET.targetOffsetMs) {
|
||||
bundle.putLong(keyForField(FIELD_TARGET_OFFSET_MS), targetOffsetMs);
|
||||
bundle.putLong(FIELD_TARGET_OFFSET_MS, targetOffsetMs);
|
||||
}
|
||||
if (minOffsetMs != UNSET.minOffsetMs) {
|
||||
bundle.putLong(keyForField(FIELD_MIN_OFFSET_MS), minOffsetMs);
|
||||
bundle.putLong(FIELD_MIN_OFFSET_MS, minOffsetMs);
|
||||
}
|
||||
if (maxOffsetMs != UNSET.maxOffsetMs) {
|
||||
bundle.putLong(keyForField(FIELD_MAX_OFFSET_MS), maxOffsetMs);
|
||||
bundle.putLong(FIELD_MAX_OFFSET_MS, maxOffsetMs);
|
||||
}
|
||||
if (minPlaybackSpeed != UNSET.minPlaybackSpeed) {
|
||||
bundle.putFloat(keyForField(FIELD_MIN_PLAYBACK_SPEED), minPlaybackSpeed);
|
||||
bundle.putFloat(FIELD_MIN_PLAYBACK_SPEED, minPlaybackSpeed);
|
||||
}
|
||||
if (maxPlaybackSpeed != UNSET.maxPlaybackSpeed) {
|
||||
bundle.putFloat(keyForField(FIELD_MAX_PLAYBACK_SPEED), maxPlaybackSpeed);
|
||||
bundle.putFloat(FIELD_MAX_PLAYBACK_SPEED, maxPlaybackSpeed);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -1349,22 +1331,13 @@ public final class MediaItem implements Bundleable {
|
||||
public static final Creator<LiveConfiguration> CREATOR =
|
||||
bundle ->
|
||||
new LiveConfiguration(
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_TARGET_OFFSET_MS), /* defaultValue= */ UNSET.targetOffsetMs),
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_MIN_OFFSET_MS), /* defaultValue= */ UNSET.minOffsetMs),
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_MAX_OFFSET_MS), /* defaultValue= */ UNSET.maxOffsetMs),
|
||||
bundle.getLong(FIELD_TARGET_OFFSET_MS, /* defaultValue= */ UNSET.targetOffsetMs),
|
||||
bundle.getLong(FIELD_MIN_OFFSET_MS, /* defaultValue= */ UNSET.minOffsetMs),
|
||||
bundle.getLong(FIELD_MAX_OFFSET_MS, /* defaultValue= */ UNSET.maxOffsetMs),
|
||||
bundle.getFloat(
|
||||
keyForField(FIELD_MIN_PLAYBACK_SPEED),
|
||||
/* defaultValue= */ UNSET.minPlaybackSpeed),
|
||||
FIELD_MIN_PLAYBACK_SPEED, /* defaultValue= */ UNSET.minPlaybackSpeed),
|
||||
bundle.getFloat(
|
||||
keyForField(FIELD_MAX_PLAYBACK_SPEED),
|
||||
/* defaultValue= */ UNSET.maxPlaybackSpeed));
|
||||
|
||||
private static String keyForField(@LiveConfiguration.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
FIELD_MAX_PLAYBACK_SPEED, /* defaultValue= */ UNSET.maxPlaybackSpeed));
|
||||
}
|
||||
|
||||
/** Properties for a text track. */
|
||||
@ -1756,43 +1729,30 @@ public final class MediaItem implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_START_POSITION_MS,
|
||||
FIELD_END_POSITION_MS,
|
||||
FIELD_RELATIVE_TO_LIVE_WINDOW,
|
||||
FIELD_RELATIVE_TO_DEFAULT_POSITION,
|
||||
FIELD_STARTS_AT_KEY_FRAME
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_START_POSITION_MS = 0;
|
||||
private static final int FIELD_END_POSITION_MS = 1;
|
||||
private static final int FIELD_RELATIVE_TO_LIVE_WINDOW = 2;
|
||||
private static final int FIELD_RELATIVE_TO_DEFAULT_POSITION = 3;
|
||||
private static final int FIELD_STARTS_AT_KEY_FRAME = 4;
|
||||
private static final String FIELD_START_POSITION_MS = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_END_POSITION_MS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_RELATIVE_TO_LIVE_WINDOW = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_RELATIVE_TO_DEFAULT_POSITION = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_STARTS_AT_KEY_FRAME = Util.intToStringMaxRadix(4);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (startPositionMs != UNSET.startPositionMs) {
|
||||
bundle.putLong(keyForField(FIELD_START_POSITION_MS), startPositionMs);
|
||||
bundle.putLong(FIELD_START_POSITION_MS, startPositionMs);
|
||||
}
|
||||
if (endPositionMs != UNSET.endPositionMs) {
|
||||
bundle.putLong(keyForField(FIELD_END_POSITION_MS), endPositionMs);
|
||||
bundle.putLong(FIELD_END_POSITION_MS, endPositionMs);
|
||||
}
|
||||
if (relativeToLiveWindow != UNSET.relativeToLiveWindow) {
|
||||
bundle.putBoolean(keyForField(FIELD_RELATIVE_TO_LIVE_WINDOW), relativeToLiveWindow);
|
||||
bundle.putBoolean(FIELD_RELATIVE_TO_LIVE_WINDOW, relativeToLiveWindow);
|
||||
}
|
||||
if (relativeToDefaultPosition != UNSET.relativeToDefaultPosition) {
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_RELATIVE_TO_DEFAULT_POSITION), relativeToDefaultPosition);
|
||||
bundle.putBoolean(FIELD_RELATIVE_TO_DEFAULT_POSITION, relativeToDefaultPosition);
|
||||
}
|
||||
if (startsAtKeyFrame != UNSET.startsAtKeyFrame) {
|
||||
bundle.putBoolean(keyForField(FIELD_STARTS_AT_KEY_FRAME), startsAtKeyFrame);
|
||||
bundle.putBoolean(FIELD_STARTS_AT_KEY_FRAME, startsAtKeyFrame);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -1804,29 +1764,21 @@ public final class MediaItem implements Bundleable {
|
||||
new ClippingConfiguration.Builder()
|
||||
.setStartPositionMs(
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_START_POSITION_MS),
|
||||
/* defaultValue= */ UNSET.startPositionMs))
|
||||
FIELD_START_POSITION_MS, /* defaultValue= */ UNSET.startPositionMs))
|
||||
.setEndPositionMs(
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_END_POSITION_MS),
|
||||
/* defaultValue= */ UNSET.endPositionMs))
|
||||
bundle.getLong(FIELD_END_POSITION_MS, /* defaultValue= */ UNSET.endPositionMs))
|
||||
.setRelativeToLiveWindow(
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_RELATIVE_TO_LIVE_WINDOW),
|
||||
FIELD_RELATIVE_TO_LIVE_WINDOW,
|
||||
/* defaultValue= */ UNSET.relativeToLiveWindow))
|
||||
.setRelativeToDefaultPosition(
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_RELATIVE_TO_DEFAULT_POSITION),
|
||||
FIELD_RELATIVE_TO_DEFAULT_POSITION,
|
||||
/* defaultValue= */ UNSET.relativeToDefaultPosition))
|
||||
.setStartsAtKeyFrame(
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_STARTS_AT_KEY_FRAME),
|
||||
/* defaultValue= */ UNSET.startsAtKeyFrame))
|
||||
FIELD_STARTS_AT_KEY_FRAME, /* defaultValue= */ UNSET.startsAtKeyFrame))
|
||||
.buildClippingProperties();
|
||||
|
||||
private static String keyForField(@ClippingConfiguration.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1945,28 +1897,22 @@ public final class MediaItem implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_MEDIA_URI, FIELD_SEARCH_QUERY, FIELD_EXTRAS})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_MEDIA_URI = 0;
|
||||
private static final int FIELD_SEARCH_QUERY = 1;
|
||||
private static final int FIELD_EXTRAS = 2;
|
||||
private static final String FIELD_MEDIA_URI = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_SEARCH_QUERY = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (mediaUri != null) {
|
||||
bundle.putParcelable(keyForField(FIELD_MEDIA_URI), mediaUri);
|
||||
bundle.putParcelable(FIELD_MEDIA_URI, mediaUri);
|
||||
}
|
||||
if (searchQuery != null) {
|
||||
bundle.putString(keyForField(FIELD_SEARCH_QUERY), searchQuery);
|
||||
bundle.putString(FIELD_SEARCH_QUERY, searchQuery);
|
||||
}
|
||||
if (extras != null) {
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -1976,14 +1922,10 @@ public final class MediaItem implements Bundleable {
|
||||
public static final Creator<RequestMetadata> CREATOR =
|
||||
bundle ->
|
||||
new RequestMetadata.Builder()
|
||||
.setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI)))
|
||||
.setSearchQuery(bundle.getString(keyForField(FIELD_SEARCH_QUERY)))
|
||||
.setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS)))
|
||||
.setMediaUri(bundle.getParcelable(FIELD_MEDIA_URI))
|
||||
.setSearchQuery(bundle.getString(FIELD_SEARCH_QUERY))
|
||||
.setExtras(bundle.getBundle(FIELD_EXTRAS))
|
||||
.build();
|
||||
|
||||
private static String keyForField(@RequestMetadata.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2079,24 +2021,11 @@ public final class MediaItem implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_MEDIA_ID,
|
||||
FIELD_LIVE_CONFIGURATION,
|
||||
FIELD_MEDIA_METADATA,
|
||||
FIELD_CLIPPING_PROPERTIES,
|
||||
FIELD_REQUEST_METADATA
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_MEDIA_ID = 0;
|
||||
private static final int FIELD_LIVE_CONFIGURATION = 1;
|
||||
private static final int FIELD_MEDIA_METADATA = 2;
|
||||
private static final int FIELD_CLIPPING_PROPERTIES = 3;
|
||||
private static final int FIELD_REQUEST_METADATA = 4;
|
||||
private static final String FIELD_MEDIA_ID = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_LIVE_CONFIGURATION = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_MEDIA_METADATA = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_CLIPPING_PROPERTIES = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_REQUEST_METADATA = Util.intToStringMaxRadix(4);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -2109,19 +2038,19 @@ public final class MediaItem implements Bundleable {
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (!mediaId.equals(DEFAULT_MEDIA_ID)) {
|
||||
bundle.putString(keyForField(FIELD_MEDIA_ID), mediaId);
|
||||
bundle.putString(FIELD_MEDIA_ID, mediaId);
|
||||
}
|
||||
if (!liveConfiguration.equals(LiveConfiguration.UNSET)) {
|
||||
bundle.putBundle(keyForField(FIELD_LIVE_CONFIGURATION), liveConfiguration.toBundle());
|
||||
bundle.putBundle(FIELD_LIVE_CONFIGURATION, liveConfiguration.toBundle());
|
||||
}
|
||||
if (!mediaMetadata.equals(MediaMetadata.EMPTY)) {
|
||||
bundle.putBundle(keyForField(FIELD_MEDIA_METADATA), mediaMetadata.toBundle());
|
||||
bundle.putBundle(FIELD_MEDIA_METADATA, mediaMetadata.toBundle());
|
||||
}
|
||||
if (!clippingConfiguration.equals(ClippingConfiguration.UNSET)) {
|
||||
bundle.putBundle(keyForField(FIELD_CLIPPING_PROPERTIES), clippingConfiguration.toBundle());
|
||||
bundle.putBundle(FIELD_CLIPPING_PROPERTIES, clippingConfiguration.toBundle());
|
||||
}
|
||||
if (!requestMetadata.equals(RequestMetadata.EMPTY)) {
|
||||
bundle.putBundle(keyForField(FIELD_REQUEST_METADATA), requestMetadata.toBundle());
|
||||
bundle.putBundle(FIELD_REQUEST_METADATA, requestMetadata.toBundle());
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -2135,31 +2064,29 @@ public final class MediaItem implements Bundleable {
|
||||
|
||||
@SuppressWarnings("deprecation") // Unbundling to ClippingProperties while it still exists.
|
||||
private static MediaItem fromBundle(Bundle bundle) {
|
||||
String mediaId = checkNotNull(bundle.getString(keyForField(FIELD_MEDIA_ID), DEFAULT_MEDIA_ID));
|
||||
@Nullable
|
||||
Bundle liveConfigurationBundle = bundle.getBundle(keyForField(FIELD_LIVE_CONFIGURATION));
|
||||
String mediaId = checkNotNull(bundle.getString(FIELD_MEDIA_ID, DEFAULT_MEDIA_ID));
|
||||
@Nullable Bundle liveConfigurationBundle = bundle.getBundle(FIELD_LIVE_CONFIGURATION);
|
||||
LiveConfiguration liveConfiguration;
|
||||
if (liveConfigurationBundle == null) {
|
||||
liveConfiguration = LiveConfiguration.UNSET;
|
||||
} else {
|
||||
liveConfiguration = LiveConfiguration.CREATOR.fromBundle(liveConfigurationBundle);
|
||||
}
|
||||
@Nullable Bundle mediaMetadataBundle = bundle.getBundle(keyForField(FIELD_MEDIA_METADATA));
|
||||
@Nullable Bundle mediaMetadataBundle = bundle.getBundle(FIELD_MEDIA_METADATA);
|
||||
MediaMetadata mediaMetadata;
|
||||
if (mediaMetadataBundle == null) {
|
||||
mediaMetadata = MediaMetadata.EMPTY;
|
||||
} else {
|
||||
mediaMetadata = MediaMetadata.CREATOR.fromBundle(mediaMetadataBundle);
|
||||
}
|
||||
@Nullable
|
||||
Bundle clippingConfigurationBundle = bundle.getBundle(keyForField(FIELD_CLIPPING_PROPERTIES));
|
||||
@Nullable Bundle clippingConfigurationBundle = bundle.getBundle(FIELD_CLIPPING_PROPERTIES);
|
||||
ClippingProperties clippingConfiguration;
|
||||
if (clippingConfigurationBundle == null) {
|
||||
clippingConfiguration = ClippingProperties.UNSET;
|
||||
} else {
|
||||
clippingConfiguration = ClippingConfiguration.CREATOR.fromBundle(clippingConfigurationBundle);
|
||||
}
|
||||
@Nullable Bundle requestMetadataBundle = bundle.getBundle(keyForField(FIELD_REQUEST_METADATA));
|
||||
@Nullable Bundle requestMetadataBundle = bundle.getBundle(FIELD_REQUEST_METADATA);
|
||||
RequestMetadata requestMetadata;
|
||||
if (requestMetadataBundle == null) {
|
||||
requestMetadata = RequestMetadata.EMPTY;
|
||||
@ -2174,8 +2101,4 @@ public final class MediaItem implements Bundleable {
|
||||
mediaMetadata,
|
||||
requestMetadata);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -1103,184 +1103,143 @@ public final class MediaMetadata implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TITLE,
|
||||
FIELD_ARTIST,
|
||||
FIELD_ALBUM_TITLE,
|
||||
FIELD_ALBUM_ARTIST,
|
||||
FIELD_DISPLAY_TITLE,
|
||||
FIELD_SUBTITLE,
|
||||
FIELD_DESCRIPTION,
|
||||
FIELD_MEDIA_URI,
|
||||
FIELD_USER_RATING,
|
||||
FIELD_OVERALL_RATING,
|
||||
FIELD_ARTWORK_DATA,
|
||||
FIELD_ARTWORK_DATA_TYPE,
|
||||
FIELD_ARTWORK_URI,
|
||||
FIELD_TRACK_NUMBER,
|
||||
FIELD_TOTAL_TRACK_COUNT,
|
||||
FIELD_FOLDER_TYPE,
|
||||
FIELD_IS_PLAYABLE,
|
||||
FIELD_RECORDING_YEAR,
|
||||
FIELD_RECORDING_MONTH,
|
||||
FIELD_RECORDING_DAY,
|
||||
FIELD_RELEASE_YEAR,
|
||||
FIELD_RELEASE_MONTH,
|
||||
FIELD_RELEASE_DAY,
|
||||
FIELD_WRITER,
|
||||
FIELD_COMPOSER,
|
||||
FIELD_CONDUCTOR,
|
||||
FIELD_DISC_NUMBER,
|
||||
FIELD_TOTAL_DISC_COUNT,
|
||||
FIELD_GENRE,
|
||||
FIELD_COMPILATION,
|
||||
FIELD_STATION,
|
||||
FIELD_MEDIA_TYPE,
|
||||
FIELD_IS_BROWSABLE,
|
||||
FIELD_EXTRAS,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TITLE = 0;
|
||||
private static final int FIELD_ARTIST = 1;
|
||||
private static final int FIELD_ALBUM_TITLE = 2;
|
||||
private static final int FIELD_ALBUM_ARTIST = 3;
|
||||
private static final int FIELD_DISPLAY_TITLE = 4;
|
||||
private static final int FIELD_SUBTITLE = 5;
|
||||
private static final int FIELD_DESCRIPTION = 6;
|
||||
private static final int FIELD_MEDIA_URI = 7;
|
||||
private static final int FIELD_USER_RATING = 8;
|
||||
private static final int FIELD_OVERALL_RATING = 9;
|
||||
private static final int FIELD_ARTWORK_DATA = 10;
|
||||
private static final int FIELD_ARTWORK_URI = 11;
|
||||
private static final int FIELD_TRACK_NUMBER = 12;
|
||||
private static final int FIELD_TOTAL_TRACK_COUNT = 13;
|
||||
private static final int FIELD_FOLDER_TYPE = 14;
|
||||
private static final int FIELD_IS_PLAYABLE = 15;
|
||||
private static final int FIELD_RECORDING_YEAR = 16;
|
||||
private static final int FIELD_RECORDING_MONTH = 17;
|
||||
private static final int FIELD_RECORDING_DAY = 18;
|
||||
private static final int FIELD_RELEASE_YEAR = 19;
|
||||
private static final int FIELD_RELEASE_MONTH = 20;
|
||||
private static final int FIELD_RELEASE_DAY = 21;
|
||||
private static final int FIELD_WRITER = 22;
|
||||
private static final int FIELD_COMPOSER = 23;
|
||||
private static final int FIELD_CONDUCTOR = 24;
|
||||
private static final int FIELD_DISC_NUMBER = 25;
|
||||
private static final int FIELD_TOTAL_DISC_COUNT = 26;
|
||||
private static final int FIELD_GENRE = 27;
|
||||
private static final int FIELD_COMPILATION = 28;
|
||||
private static final int FIELD_ARTWORK_DATA_TYPE = 29;
|
||||
private static final int FIELD_STATION = 30;
|
||||
private static final int FIELD_MEDIA_TYPE = 31;
|
||||
private static final int FIELD_IS_BROWSABLE = 32;
|
||||
private static final int FIELD_EXTRAS = 1000;
|
||||
private static final String FIELD_TITLE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_ARTIST = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_ALBUM_TITLE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_ALBUM_ARTIST = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_DISPLAY_TITLE = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_SUBTITLE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_DESCRIPTION = Util.intToStringMaxRadix(6);
|
||||
// 7 is reserved to maintain backward compatibility for a previously defined field.
|
||||
private static final String FIELD_USER_RATING = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_OVERALL_RATING = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_ARTWORK_DATA = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_ARTWORK_URI = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_TRACK_NUMBER = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_TOTAL_TRACK_COUNT = Util.intToStringMaxRadix(13);
|
||||
private static final String FIELD_FOLDER_TYPE = Util.intToStringMaxRadix(14);
|
||||
private static final String FIELD_IS_PLAYABLE = Util.intToStringMaxRadix(15);
|
||||
private static final String FIELD_RECORDING_YEAR = Util.intToStringMaxRadix(16);
|
||||
private static final String FIELD_RECORDING_MONTH = Util.intToStringMaxRadix(17);
|
||||
private static final String FIELD_RECORDING_DAY = Util.intToStringMaxRadix(18);
|
||||
private static final String FIELD_RELEASE_YEAR = Util.intToStringMaxRadix(19);
|
||||
private static final String FIELD_RELEASE_MONTH = Util.intToStringMaxRadix(20);
|
||||
private static final String FIELD_RELEASE_DAY = Util.intToStringMaxRadix(21);
|
||||
private static final String FIELD_WRITER = Util.intToStringMaxRadix(22);
|
||||
private static final String FIELD_COMPOSER = Util.intToStringMaxRadix(23);
|
||||
private static final String FIELD_CONDUCTOR = Util.intToStringMaxRadix(24);
|
||||
private static final String FIELD_DISC_NUMBER = Util.intToStringMaxRadix(25);
|
||||
private static final String FIELD_TOTAL_DISC_COUNT = Util.intToStringMaxRadix(26);
|
||||
private static final String FIELD_GENRE = Util.intToStringMaxRadix(27);
|
||||
private static final String FIELD_COMPILATION = Util.intToStringMaxRadix(28);
|
||||
private static final String FIELD_ARTWORK_DATA_TYPE = Util.intToStringMaxRadix(29);
|
||||
private static final String FIELD_STATION = Util.intToStringMaxRadix(30);
|
||||
private static final String FIELD_MEDIA_TYPE = Util.intToStringMaxRadix(31);
|
||||
private static final String FIELD_IS_BROWSABLE = Util.intToStringMaxRadix(32);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(1000);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (title != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_TITLE), title);
|
||||
bundle.putCharSequence(FIELD_TITLE, title);
|
||||
}
|
||||
if (artist != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_ARTIST), artist);
|
||||
bundle.putCharSequence(FIELD_ARTIST, artist);
|
||||
}
|
||||
if (albumTitle != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_TITLE), albumTitle);
|
||||
bundle.putCharSequence(FIELD_ALBUM_TITLE, albumTitle);
|
||||
}
|
||||
if (albumArtist != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_ARTIST), albumArtist);
|
||||
bundle.putCharSequence(FIELD_ALBUM_ARTIST, albumArtist);
|
||||
}
|
||||
if (displayTitle != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_DISPLAY_TITLE), displayTitle);
|
||||
bundle.putCharSequence(FIELD_DISPLAY_TITLE, displayTitle);
|
||||
}
|
||||
if (subtitle != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_SUBTITLE), subtitle);
|
||||
bundle.putCharSequence(FIELD_SUBTITLE, subtitle);
|
||||
}
|
||||
if (description != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_DESCRIPTION), description);
|
||||
bundle.putCharSequence(FIELD_DESCRIPTION, description);
|
||||
}
|
||||
if (artworkData != null) {
|
||||
bundle.putByteArray(keyForField(FIELD_ARTWORK_DATA), artworkData);
|
||||
bundle.putByteArray(FIELD_ARTWORK_DATA, artworkData);
|
||||
}
|
||||
if (artworkUri != null) {
|
||||
bundle.putParcelable(keyForField(FIELD_ARTWORK_URI), artworkUri);
|
||||
bundle.putParcelable(FIELD_ARTWORK_URI, artworkUri);
|
||||
}
|
||||
if (writer != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_WRITER), writer);
|
||||
bundle.putCharSequence(FIELD_WRITER, writer);
|
||||
}
|
||||
if (composer != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_COMPOSER), composer);
|
||||
bundle.putCharSequence(FIELD_COMPOSER, composer);
|
||||
}
|
||||
if (conductor != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_CONDUCTOR), conductor);
|
||||
bundle.putCharSequence(FIELD_CONDUCTOR, conductor);
|
||||
}
|
||||
if (genre != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_GENRE), genre);
|
||||
bundle.putCharSequence(FIELD_GENRE, genre);
|
||||
}
|
||||
if (compilation != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_COMPILATION), compilation);
|
||||
bundle.putCharSequence(FIELD_COMPILATION, compilation);
|
||||
}
|
||||
if (station != null) {
|
||||
bundle.putCharSequence(keyForField(FIELD_STATION), station);
|
||||
bundle.putCharSequence(FIELD_STATION, station);
|
||||
}
|
||||
if (userRating != null) {
|
||||
bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle());
|
||||
bundle.putBundle(FIELD_USER_RATING, userRating.toBundle());
|
||||
}
|
||||
if (overallRating != null) {
|
||||
bundle.putBundle(keyForField(FIELD_OVERALL_RATING), overallRating.toBundle());
|
||||
bundle.putBundle(FIELD_OVERALL_RATING, overallRating.toBundle());
|
||||
}
|
||||
if (trackNumber != null) {
|
||||
bundle.putInt(keyForField(FIELD_TRACK_NUMBER), trackNumber);
|
||||
bundle.putInt(FIELD_TRACK_NUMBER, trackNumber);
|
||||
}
|
||||
if (totalTrackCount != null) {
|
||||
bundle.putInt(keyForField(FIELD_TOTAL_TRACK_COUNT), totalTrackCount);
|
||||
bundle.putInt(FIELD_TOTAL_TRACK_COUNT, totalTrackCount);
|
||||
}
|
||||
if (folderType != null) {
|
||||
bundle.putInt(keyForField(FIELD_FOLDER_TYPE), folderType);
|
||||
bundle.putInt(FIELD_FOLDER_TYPE, folderType);
|
||||
}
|
||||
if (isBrowsable != null) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_BROWSABLE), isBrowsable);
|
||||
bundle.putBoolean(FIELD_IS_BROWSABLE, isBrowsable);
|
||||
}
|
||||
if (isPlayable != null) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLAYABLE), isPlayable);
|
||||
bundle.putBoolean(FIELD_IS_PLAYABLE, isPlayable);
|
||||
}
|
||||
if (recordingYear != null) {
|
||||
bundle.putInt(keyForField(FIELD_RECORDING_YEAR), recordingYear);
|
||||
bundle.putInt(FIELD_RECORDING_YEAR, recordingYear);
|
||||
}
|
||||
if (recordingMonth != null) {
|
||||
bundle.putInt(keyForField(FIELD_RECORDING_MONTH), recordingMonth);
|
||||
bundle.putInt(FIELD_RECORDING_MONTH, recordingMonth);
|
||||
}
|
||||
if (recordingDay != null) {
|
||||
bundle.putInt(keyForField(FIELD_RECORDING_DAY), recordingDay);
|
||||
bundle.putInt(FIELD_RECORDING_DAY, recordingDay);
|
||||
}
|
||||
if (releaseYear != null) {
|
||||
bundle.putInt(keyForField(FIELD_RELEASE_YEAR), releaseYear);
|
||||
bundle.putInt(FIELD_RELEASE_YEAR, releaseYear);
|
||||
}
|
||||
if (releaseMonth != null) {
|
||||
bundle.putInt(keyForField(FIELD_RELEASE_MONTH), releaseMonth);
|
||||
bundle.putInt(FIELD_RELEASE_MONTH, releaseMonth);
|
||||
}
|
||||
if (releaseDay != null) {
|
||||
bundle.putInt(keyForField(FIELD_RELEASE_DAY), releaseDay);
|
||||
bundle.putInt(FIELD_RELEASE_DAY, releaseDay);
|
||||
}
|
||||
if (discNumber != null) {
|
||||
bundle.putInt(keyForField(FIELD_DISC_NUMBER), discNumber);
|
||||
bundle.putInt(FIELD_DISC_NUMBER, discNumber);
|
||||
}
|
||||
if (totalDiscCount != null) {
|
||||
bundle.putInt(keyForField(FIELD_TOTAL_DISC_COUNT), totalDiscCount);
|
||||
bundle.putInt(FIELD_TOTAL_DISC_COUNT, totalDiscCount);
|
||||
}
|
||||
if (artworkDataType != null) {
|
||||
bundle.putInt(keyForField(FIELD_ARTWORK_DATA_TYPE), artworkDataType);
|
||||
bundle.putInt(FIELD_ARTWORK_DATA_TYPE, artworkDataType);
|
||||
}
|
||||
if (mediaType != null) {
|
||||
bundle.putInt(keyForField(FIELD_MEDIA_TYPE), mediaType);
|
||||
bundle.putInt(FIELD_MEDIA_TYPE, mediaType);
|
||||
}
|
||||
if (extras != null) {
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -1291,89 +1250,85 @@ public final class MediaMetadata implements Bundleable {
|
||||
private static MediaMetadata fromBundle(Bundle bundle) {
|
||||
Builder builder = new Builder();
|
||||
builder
|
||||
.setTitle(bundle.getCharSequence(keyForField(FIELD_TITLE)))
|
||||
.setArtist(bundle.getCharSequence(keyForField(FIELD_ARTIST)))
|
||||
.setAlbumTitle(bundle.getCharSequence(keyForField(FIELD_ALBUM_TITLE)))
|
||||
.setAlbumArtist(bundle.getCharSequence(keyForField(FIELD_ALBUM_ARTIST)))
|
||||
.setDisplayTitle(bundle.getCharSequence(keyForField(FIELD_DISPLAY_TITLE)))
|
||||
.setSubtitle(bundle.getCharSequence(keyForField(FIELD_SUBTITLE)))
|
||||
.setDescription(bundle.getCharSequence(keyForField(FIELD_DESCRIPTION)))
|
||||
.setTitle(bundle.getCharSequence(FIELD_TITLE))
|
||||
.setArtist(bundle.getCharSequence(FIELD_ARTIST))
|
||||
.setAlbumTitle(bundle.getCharSequence(FIELD_ALBUM_TITLE))
|
||||
.setAlbumArtist(bundle.getCharSequence(FIELD_ALBUM_ARTIST))
|
||||
.setDisplayTitle(bundle.getCharSequence(FIELD_DISPLAY_TITLE))
|
||||
.setSubtitle(bundle.getCharSequence(FIELD_SUBTITLE))
|
||||
.setDescription(bundle.getCharSequence(FIELD_DESCRIPTION))
|
||||
.setArtworkData(
|
||||
bundle.getByteArray(keyForField(FIELD_ARTWORK_DATA)),
|
||||
bundle.containsKey(keyForField(FIELD_ARTWORK_DATA_TYPE))
|
||||
? bundle.getInt(keyForField(FIELD_ARTWORK_DATA_TYPE))
|
||||
bundle.getByteArray(FIELD_ARTWORK_DATA),
|
||||
bundle.containsKey(FIELD_ARTWORK_DATA_TYPE)
|
||||
? bundle.getInt(FIELD_ARTWORK_DATA_TYPE)
|
||||
: null)
|
||||
.setArtworkUri(bundle.getParcelable(keyForField(FIELD_ARTWORK_URI)))
|
||||
.setWriter(bundle.getCharSequence(keyForField(FIELD_WRITER)))
|
||||
.setComposer(bundle.getCharSequence(keyForField(FIELD_COMPOSER)))
|
||||
.setConductor(bundle.getCharSequence(keyForField(FIELD_CONDUCTOR)))
|
||||
.setGenre(bundle.getCharSequence(keyForField(FIELD_GENRE)))
|
||||
.setCompilation(bundle.getCharSequence(keyForField(FIELD_COMPILATION)))
|
||||
.setStation(bundle.getCharSequence(keyForField(FIELD_STATION)))
|
||||
.setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS)));
|
||||
.setArtworkUri(bundle.getParcelable(FIELD_ARTWORK_URI))
|
||||
.setWriter(bundle.getCharSequence(FIELD_WRITER))
|
||||
.setComposer(bundle.getCharSequence(FIELD_COMPOSER))
|
||||
.setConductor(bundle.getCharSequence(FIELD_CONDUCTOR))
|
||||
.setGenre(bundle.getCharSequence(FIELD_GENRE))
|
||||
.setCompilation(bundle.getCharSequence(FIELD_COMPILATION))
|
||||
.setStation(bundle.getCharSequence(FIELD_STATION))
|
||||
.setExtras(bundle.getBundle(FIELD_EXTRAS));
|
||||
|
||||
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(keyForField(FIELD_USER_RATING));
|
||||
if (bundle.containsKey(FIELD_USER_RATING)) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(FIELD_USER_RATING);
|
||||
if (fieldBundle != null) {
|
||||
builder.setUserRating(Rating.CREATOR.fromBundle(fieldBundle));
|
||||
}
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_OVERALL_RATING))) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(keyForField(FIELD_OVERALL_RATING));
|
||||
if (bundle.containsKey(FIELD_OVERALL_RATING)) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(FIELD_OVERALL_RATING);
|
||||
if (fieldBundle != null) {
|
||||
builder.setOverallRating(Rating.CREATOR.fromBundle(fieldBundle));
|
||||
}
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_TRACK_NUMBER))) {
|
||||
builder.setTrackNumber(bundle.getInt(keyForField(FIELD_TRACK_NUMBER)));
|
||||
if (bundle.containsKey(FIELD_TRACK_NUMBER)) {
|
||||
builder.setTrackNumber(bundle.getInt(FIELD_TRACK_NUMBER));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_TOTAL_TRACK_COUNT))) {
|
||||
builder.setTotalTrackCount(bundle.getInt(keyForField(FIELD_TOTAL_TRACK_COUNT)));
|
||||
if (bundle.containsKey(FIELD_TOTAL_TRACK_COUNT)) {
|
||||
builder.setTotalTrackCount(bundle.getInt(FIELD_TOTAL_TRACK_COUNT));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_FOLDER_TYPE))) {
|
||||
builder.setFolderType(bundle.getInt(keyForField(FIELD_FOLDER_TYPE)));
|
||||
if (bundle.containsKey(FIELD_FOLDER_TYPE)) {
|
||||
builder.setFolderType(bundle.getInt(FIELD_FOLDER_TYPE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_IS_BROWSABLE))) {
|
||||
builder.setIsBrowsable(bundle.getBoolean(keyForField(FIELD_IS_BROWSABLE)));
|
||||
if (bundle.containsKey(FIELD_IS_BROWSABLE)) {
|
||||
builder.setIsBrowsable(bundle.getBoolean(FIELD_IS_BROWSABLE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_IS_PLAYABLE))) {
|
||||
builder.setIsPlayable(bundle.getBoolean(keyForField(FIELD_IS_PLAYABLE)));
|
||||
if (bundle.containsKey(FIELD_IS_PLAYABLE)) {
|
||||
builder.setIsPlayable(bundle.getBoolean(FIELD_IS_PLAYABLE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RECORDING_YEAR))) {
|
||||
builder.setRecordingYear(bundle.getInt(keyForField(FIELD_RECORDING_YEAR)));
|
||||
if (bundle.containsKey(FIELD_RECORDING_YEAR)) {
|
||||
builder.setRecordingYear(bundle.getInt(FIELD_RECORDING_YEAR));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RECORDING_MONTH))) {
|
||||
builder.setRecordingMonth(bundle.getInt(keyForField(FIELD_RECORDING_MONTH)));
|
||||
if (bundle.containsKey(FIELD_RECORDING_MONTH)) {
|
||||
builder.setRecordingMonth(bundle.getInt(FIELD_RECORDING_MONTH));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RECORDING_DAY))) {
|
||||
builder.setRecordingDay(bundle.getInt(keyForField(FIELD_RECORDING_DAY)));
|
||||
if (bundle.containsKey(FIELD_RECORDING_DAY)) {
|
||||
builder.setRecordingDay(bundle.getInt(FIELD_RECORDING_DAY));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RELEASE_YEAR))) {
|
||||
builder.setReleaseYear(bundle.getInt(keyForField(FIELD_RELEASE_YEAR)));
|
||||
if (bundle.containsKey(FIELD_RELEASE_YEAR)) {
|
||||
builder.setReleaseYear(bundle.getInt(FIELD_RELEASE_YEAR));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RELEASE_MONTH))) {
|
||||
builder.setReleaseMonth(bundle.getInt(keyForField(FIELD_RELEASE_MONTH)));
|
||||
if (bundle.containsKey(FIELD_RELEASE_MONTH)) {
|
||||
builder.setReleaseMonth(bundle.getInt(FIELD_RELEASE_MONTH));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_RELEASE_DAY))) {
|
||||
builder.setReleaseDay(bundle.getInt(keyForField(FIELD_RELEASE_DAY)));
|
||||
if (bundle.containsKey(FIELD_RELEASE_DAY)) {
|
||||
builder.setReleaseDay(bundle.getInt(FIELD_RELEASE_DAY));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_DISC_NUMBER))) {
|
||||
builder.setDiscNumber(bundle.getInt(keyForField(FIELD_DISC_NUMBER)));
|
||||
if (bundle.containsKey(FIELD_DISC_NUMBER)) {
|
||||
builder.setDiscNumber(bundle.getInt(FIELD_DISC_NUMBER));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_TOTAL_DISC_COUNT))) {
|
||||
builder.setTotalDiscCount(bundle.getInt(keyForField(FIELD_TOTAL_DISC_COUNT)));
|
||||
if (bundle.containsKey(FIELD_TOTAL_DISC_COUNT)) {
|
||||
builder.setTotalDiscCount(bundle.getInt(FIELD_TOTAL_DISC_COUNT));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_MEDIA_TYPE))) {
|
||||
builder.setMediaType(bundle.getInt(keyForField(FIELD_MEDIA_TYPE)));
|
||||
if (bundle.containsKey(FIELD_MEDIA_TYPE)) {
|
||||
builder.setMediaType(bundle.getInt(FIELD_MEDIA_TYPE));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
private static @FolderType int getFolderTypeFromMediaType(@MediaType int mediaType) {
|
||||
switch (mediaType) {
|
||||
case MEDIA_TYPE_ALBUM:
|
||||
|
@ -16,18 +16,13 @@
|
||||
package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/** A rating expressed as a percentage. */
|
||||
public final class PercentageRating extends Rating {
|
||||
@ -79,20 +74,14 @@ public final class PercentageRating extends Rating {
|
||||
|
||||
private static final @RatingType int TYPE = RATING_TYPE_PERCENTAGE;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RATING_TYPE, FIELD_PERCENT})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_PERCENT = 1;
|
||||
private static final String FIELD_PERCENT = Util.intToStringMaxRadix(1);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RATING_TYPE), TYPE);
|
||||
bundle.putFloat(keyForField(FIELD_PERCENT), percent);
|
||||
bundle.putInt(FIELD_RATING_TYPE, TYPE);
|
||||
bundle.putFloat(FIELD_PERCENT, percent);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -100,14 +89,8 @@ public final class PercentageRating extends Rating {
|
||||
@UnstableApi public static final Creator<PercentageRating> CREATOR = PercentageRating::fromBundle;
|
||||
|
||||
private static PercentageRating fromBundle(Bundle bundle) {
|
||||
checkArgument(
|
||||
bundle.getInt(keyForField(FIELD_RATING_TYPE), /* defaultValue= */ RATING_TYPE_UNSET)
|
||||
== TYPE);
|
||||
float percent = bundle.getFloat(keyForField(FIELD_PERCENT), /* defaultValue= */ RATING_UNSET);
|
||||
checkArgument(bundle.getInt(FIELD_RATING_TYPE, /* defaultValue= */ RATING_TYPE_UNSET) == TYPE);
|
||||
float percent = bundle.getFloat(FIELD_PERCENT, /* defaultValue= */ RATING_UNSET);
|
||||
return percent == RATING_UNSET ? new PercentageRating() : new PercentageRating(percent);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -346,13 +346,12 @@ public class PlaybackException extends Exception implements Bundleable {
|
||||
@UnstableApi
|
||||
protected PlaybackException(Bundle bundle) {
|
||||
this(
|
||||
/* message= */ bundle.getString(keyForField(FIELD_STRING_MESSAGE)),
|
||||
/* message= */ bundle.getString(FIELD_STRING_MESSAGE),
|
||||
/* cause= */ getCauseFromBundle(bundle),
|
||||
/* errorCode= */ bundle.getInt(
|
||||
keyForField(FIELD_INT_ERROR_CODE), /* defaultValue= */ ERROR_CODE_UNSPECIFIED),
|
||||
FIELD_INT_ERROR_CODE, /* defaultValue= */ ERROR_CODE_UNSPECIFIED),
|
||||
/* timestampMs= */ bundle.getLong(
|
||||
keyForField(FIELD_LONG_TIMESTAMP_MS),
|
||||
/* defaultValue= */ SystemClock.elapsedRealtime()));
|
||||
FIELD_LONG_TIMESTAMP_MS, /* defaultValue= */ SystemClock.elapsedRealtime()));
|
||||
}
|
||||
|
||||
/** Creates a new instance using the given values. */
|
||||
@ -401,18 +400,18 @@ public class PlaybackException extends Exception implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
private static final int FIELD_INT_ERROR_CODE = 0;
|
||||
private static final int FIELD_LONG_TIMESTAMP_MS = 1;
|
||||
private static final int FIELD_STRING_MESSAGE = 2;
|
||||
private static final int FIELD_STRING_CAUSE_CLASS_NAME = 3;
|
||||
private static final int FIELD_STRING_CAUSE_MESSAGE = 4;
|
||||
private static final String FIELD_INT_ERROR_CODE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_LONG_TIMESTAMP_MS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_STRING_MESSAGE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_STRING_CAUSE_CLASS_NAME = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_STRING_CAUSE_MESSAGE = Util.intToStringMaxRadix(4);
|
||||
|
||||
/**
|
||||
* Defines a minimum field ID value for subclasses to use when implementing {@link #toBundle()}
|
||||
* and {@link Bundleable.Creator}.
|
||||
*
|
||||
* <p>Subclasses should obtain their {@link Bundle Bundle's} field keys by applying a non-negative
|
||||
* offset on this constant and passing the result to {@link #keyForField(int)}.
|
||||
* offset on this constant and passing the result to {@link Util#intToStringMaxRadix(int)}.
|
||||
*/
|
||||
@UnstableApi protected static final int FIELD_CUSTOM_ID_BASE = 1000;
|
||||
|
||||
@ -424,29 +423,17 @@ public class PlaybackException extends Exception implements Bundleable {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_INT_ERROR_CODE), errorCode);
|
||||
bundle.putLong(keyForField(FIELD_LONG_TIMESTAMP_MS), timestampMs);
|
||||
bundle.putString(keyForField(FIELD_STRING_MESSAGE), getMessage());
|
||||
bundle.putInt(FIELD_INT_ERROR_CODE, errorCode);
|
||||
bundle.putLong(FIELD_LONG_TIMESTAMP_MS, timestampMs);
|
||||
bundle.putString(FIELD_STRING_MESSAGE, getMessage());
|
||||
@Nullable Throwable cause = getCause();
|
||||
if (cause != null) {
|
||||
bundle.putString(keyForField(FIELD_STRING_CAUSE_CLASS_NAME), cause.getClass().getName());
|
||||
bundle.putString(keyForField(FIELD_STRING_CAUSE_MESSAGE), cause.getMessage());
|
||||
bundle.putString(FIELD_STRING_CAUSE_CLASS_NAME, cause.getClass().getName());
|
||||
bundle.putString(FIELD_STRING_CAUSE_MESSAGE, cause.getMessage());
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given field number to a string which can be used as a field key when implementing
|
||||
* {@link #toBundle()} and {@link Bundleable.Creator}.
|
||||
*
|
||||
* <p>Subclasses should use {@code field} values greater than or equal to {@link
|
||||
* #FIELD_CUSTOM_ID_BASE}.
|
||||
*/
|
||||
@UnstableApi
|
||||
protected static String keyForField(int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
// Creates a new {@link Throwable} with possibly {@code null} message.
|
||||
@SuppressWarnings("nullness:argument")
|
||||
private static Throwable createThrowable(Class<?> clazz, @Nullable String message)
|
||||
@ -462,8 +449,8 @@ public class PlaybackException extends Exception implements Bundleable {
|
||||
|
||||
@Nullable
|
||||
private static Throwable getCauseFromBundle(Bundle bundle) {
|
||||
@Nullable String causeClassName = bundle.getString(keyForField(FIELD_STRING_CAUSE_CLASS_NAME));
|
||||
@Nullable String causeMessage = bundle.getString(keyForField(FIELD_STRING_CAUSE_MESSAGE));
|
||||
@Nullable String causeClassName = bundle.getString(FIELD_STRING_CAUSE_CLASS_NAME);
|
||||
@Nullable String causeMessage = bundle.getString(FIELD_STRING_CAUSE_MESSAGE);
|
||||
@Nullable Throwable cause = null;
|
||||
if (!TextUtils.isEmpty(causeClassName)) {
|
||||
try {
|
||||
|
@ -15,20 +15,13 @@
|
||||
*/
|
||||
package androidx.media3.common;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/** Parameters that apply to playback, including speed setting. */
|
||||
public final class PlaybackParameters implements Bundleable {
|
||||
@ -122,21 +115,15 @@ public final class PlaybackParameters implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_SPEED, FIELD_PITCH})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_SPEED = 0;
|
||||
private static final int FIELD_PITCH = 1;
|
||||
private static final String FIELD_SPEED = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_PITCH = Util.intToStringMaxRadix(1);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putFloat(keyForField(FIELD_SPEED), speed);
|
||||
bundle.putFloat(keyForField(FIELD_PITCH), pitch);
|
||||
bundle.putFloat(FIELD_SPEED, speed);
|
||||
bundle.putFloat(FIELD_PITCH, pitch);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -144,12 +131,8 @@ public final class PlaybackParameters implements Bundleable {
|
||||
@UnstableApi
|
||||
public static final Creator<PlaybackParameters> CREATOR =
|
||||
bundle -> {
|
||||
float speed = bundle.getFloat(keyForField(FIELD_SPEED), /* defaultValue= */ 1f);
|
||||
float pitch = bundle.getFloat(keyForField(FIELD_PITCH), /* defaultValue= */ 1f);
|
||||
float speed = bundle.getFloat(FIELD_SPEED, /* defaultValue= */ 1f);
|
||||
float pitch = bundle.getFloat(FIELD_PITCH, /* defaultValue= */ 1f);
|
||||
return new PlaybackParameters(speed, pitch);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -268,27 +268,14 @@ public interface Player {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_MEDIA_ITEM_INDEX,
|
||||
FIELD_MEDIA_ITEM,
|
||||
FIELD_PERIOD_INDEX,
|
||||
FIELD_POSITION_MS,
|
||||
FIELD_CONTENT_POSITION_MS,
|
||||
FIELD_AD_GROUP_INDEX,
|
||||
FIELD_AD_INDEX_IN_AD_GROUP
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_MEDIA_ITEM_INDEX = 0;
|
||||
private static final int FIELD_MEDIA_ITEM = 1;
|
||||
private static final int FIELD_PERIOD_INDEX = 2;
|
||||
private static final int FIELD_POSITION_MS = 3;
|
||||
private static final int FIELD_CONTENT_POSITION_MS = 4;
|
||||
private static final int FIELD_AD_GROUP_INDEX = 5;
|
||||
private static final int FIELD_AD_INDEX_IN_AD_GROUP = 6;
|
||||
private static final String FIELD_MEDIA_ITEM_INDEX = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_MEDIA_ITEM = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_PERIOD_INDEX = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_POSITION_MS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_CONTENT_POSITION_MS = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_AD_GROUP_INDEX = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_AD_INDEX_IN_AD_GROUP = Util.intToStringMaxRadix(6);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -300,15 +287,15 @@ public interface Player {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_MEDIA_ITEM_INDEX), mediaItemIndex);
|
||||
bundle.putInt(FIELD_MEDIA_ITEM_INDEX, mediaItemIndex);
|
||||
if (mediaItem != null) {
|
||||
bundle.putBundle(keyForField(FIELD_MEDIA_ITEM), mediaItem.toBundle());
|
||||
bundle.putBundle(FIELD_MEDIA_ITEM, mediaItem.toBundle());
|
||||
}
|
||||
bundle.putInt(keyForField(FIELD_PERIOD_INDEX), periodIndex);
|
||||
bundle.putLong(keyForField(FIELD_POSITION_MS), positionMs);
|
||||
bundle.putLong(keyForField(FIELD_CONTENT_POSITION_MS), contentPositionMs);
|
||||
bundle.putInt(keyForField(FIELD_AD_GROUP_INDEX), adGroupIndex);
|
||||
bundle.putInt(keyForField(FIELD_AD_INDEX_IN_AD_GROUP), adIndexInAdGroup);
|
||||
bundle.putInt(FIELD_PERIOD_INDEX, periodIndex);
|
||||
bundle.putLong(FIELD_POSITION_MS, positionMs);
|
||||
bundle.putLong(FIELD_CONTENT_POSITION_MS, contentPositionMs);
|
||||
bundle.putInt(FIELD_AD_GROUP_INDEX, adGroupIndex);
|
||||
bundle.putInt(FIELD_AD_INDEX_IN_AD_GROUP, adIndexInAdGroup);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -316,22 +303,18 @@ public interface Player {
|
||||
@UnstableApi public static final Creator<PositionInfo> CREATOR = PositionInfo::fromBundle;
|
||||
|
||||
private static PositionInfo fromBundle(Bundle bundle) {
|
||||
int mediaItemIndex =
|
||||
bundle.getInt(keyForField(FIELD_MEDIA_ITEM_INDEX), /* defaultValue= */ C.INDEX_UNSET);
|
||||
@Nullable Bundle mediaItemBundle = bundle.getBundle(keyForField(FIELD_MEDIA_ITEM));
|
||||
int mediaItemIndex = bundle.getInt(FIELD_MEDIA_ITEM_INDEX, /* defaultValue= */ C.INDEX_UNSET);
|
||||
@Nullable Bundle mediaItemBundle = bundle.getBundle(FIELD_MEDIA_ITEM);
|
||||
@Nullable
|
||||
MediaItem mediaItem =
|
||||
mediaItemBundle == null ? null : MediaItem.CREATOR.fromBundle(mediaItemBundle);
|
||||
int periodIndex =
|
||||
bundle.getInt(keyForField(FIELD_PERIOD_INDEX), /* defaultValue= */ C.INDEX_UNSET);
|
||||
long positionMs =
|
||||
bundle.getLong(keyForField(FIELD_POSITION_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
int periodIndex = bundle.getInt(FIELD_PERIOD_INDEX, /* defaultValue= */ C.INDEX_UNSET);
|
||||
long positionMs = bundle.getLong(FIELD_POSITION_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long contentPositionMs =
|
||||
bundle.getLong(keyForField(FIELD_CONTENT_POSITION_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
int adGroupIndex =
|
||||
bundle.getInt(keyForField(FIELD_AD_GROUP_INDEX), /* defaultValue= */ C.INDEX_UNSET);
|
||||
bundle.getLong(FIELD_CONTENT_POSITION_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
int adGroupIndex = bundle.getInt(FIELD_AD_GROUP_INDEX, /* defaultValue= */ C.INDEX_UNSET);
|
||||
int adIndexInAdGroup =
|
||||
bundle.getInt(keyForField(FIELD_AD_INDEX_IN_AD_GROUP), /* defaultValue= */ C.INDEX_UNSET);
|
||||
bundle.getInt(FIELD_AD_INDEX_IN_AD_GROUP, /* defaultValue= */ C.INDEX_UNSET);
|
||||
return new PositionInfo(
|
||||
/* windowUid= */ null,
|
||||
mediaItemIndex,
|
||||
@ -343,10 +326,6 @@ public interface Player {
|
||||
adGroupIndex,
|
||||
adIndexInAdGroup);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -581,13 +560,7 @@ public interface Player {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_COMMANDS})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_COMMANDS = 0;
|
||||
private static final String FIELD_COMMANDS = Util.intToStringMaxRadix(0);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
@ -597,7 +570,7 @@ public interface Player {
|
||||
for (int i = 0; i < flags.size(); i++) {
|
||||
commandsBundle.add(flags.get(i));
|
||||
}
|
||||
bundle.putIntegerArrayList(keyForField(FIELD_COMMANDS), commandsBundle);
|
||||
bundle.putIntegerArrayList(FIELD_COMMANDS, commandsBundle);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -605,8 +578,7 @@ public interface Player {
|
||||
@UnstableApi public static final Creator<Commands> CREATOR = Commands::fromBundle;
|
||||
|
||||
private static Commands fromBundle(Bundle bundle) {
|
||||
@Nullable
|
||||
ArrayList<Integer> commands = bundle.getIntegerArrayList(keyForField(FIELD_COMMANDS));
|
||||
@Nullable ArrayList<Integer> commands = bundle.getIntegerArrayList(FIELD_COMMANDS);
|
||||
if (commands == null) {
|
||||
return Commands.EMPTY;
|
||||
}
|
||||
@ -616,10 +588,6 @@ public interface Player {
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@ -60,21 +61,14 @@ public abstract class Rating implements Bundleable {
|
||||
/* package */ static final int RATING_TYPE_STAR = 2;
|
||||
/* package */ static final int RATING_TYPE_THUMB = 3;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RATING_TYPE})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
/* package */ static final int FIELD_RATING_TYPE = 0;
|
||||
/* package */ static final String FIELD_RATING_TYPE = Util.intToStringMaxRadix(0);
|
||||
|
||||
/** Object that can restore a {@link Rating} from a {@link Bundle}. */
|
||||
@UnstableApi public static final Creator<Rating> CREATOR = Rating::fromBundle;
|
||||
|
||||
private static Rating fromBundle(Bundle bundle) {
|
||||
@RatingType
|
||||
int ratingType =
|
||||
bundle.getInt(keyForField(FIELD_RATING_TYPE), /* defaultValue= */ RATING_TYPE_UNSET);
|
||||
int ratingType = bundle.getInt(FIELD_RATING_TYPE, /* defaultValue= */ RATING_TYPE_UNSET);
|
||||
switch (ratingType) {
|
||||
case RATING_TYPE_HEART:
|
||||
return HeartRating.CREATOR.fromBundle(bundle);
|
||||
@ -89,8 +83,4 @@ public abstract class Rating implements Bundleable {
|
||||
throw new IllegalArgumentException("Unknown RatingType: " + ratingType);
|
||||
}
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -16,19 +16,14 @@
|
||||
package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/** A rating expressed as a fractional number of stars. */
|
||||
public final class StarRating extends Rating {
|
||||
@ -106,22 +101,16 @@ public final class StarRating extends Rating {
|
||||
private static final @RatingType int TYPE = RATING_TYPE_STAR;
|
||||
private static final int MAX_STARS_DEFAULT = 5;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RATING_TYPE, FIELD_MAX_STARS, FIELD_STAR_RATING})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_MAX_STARS = 1;
|
||||
private static final int FIELD_STAR_RATING = 2;
|
||||
private static final String FIELD_MAX_STARS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_STAR_RATING = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RATING_TYPE), TYPE);
|
||||
bundle.putInt(keyForField(FIELD_MAX_STARS), maxStars);
|
||||
bundle.putFloat(keyForField(FIELD_STAR_RATING), starRating);
|
||||
bundle.putInt(FIELD_RATING_TYPE, TYPE);
|
||||
bundle.putInt(FIELD_MAX_STARS, maxStars);
|
||||
bundle.putFloat(FIELD_STAR_RATING, starRating);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -129,19 +118,11 @@ public final class StarRating extends Rating {
|
||||
@UnstableApi public static final Creator<StarRating> CREATOR = StarRating::fromBundle;
|
||||
|
||||
private static StarRating fromBundle(Bundle bundle) {
|
||||
checkArgument(
|
||||
bundle.getInt(keyForField(FIELD_RATING_TYPE), /* defaultValue= */ RATING_TYPE_UNSET)
|
||||
== TYPE);
|
||||
int maxStars =
|
||||
bundle.getInt(keyForField(FIELD_MAX_STARS), /* defaultValue= */ MAX_STARS_DEFAULT);
|
||||
float starRating =
|
||||
bundle.getFloat(keyForField(FIELD_STAR_RATING), /* defaultValue= */ RATING_UNSET);
|
||||
checkArgument(bundle.getInt(FIELD_RATING_TYPE, /* defaultValue= */ RATING_TYPE_UNSET) == TYPE);
|
||||
int maxStars = bundle.getInt(FIELD_MAX_STARS, /* defaultValue= */ MAX_STARS_DEFAULT);
|
||||
float starRating = bundle.getFloat(FIELD_STAR_RATING, /* defaultValue= */ RATING_UNSET);
|
||||
return starRating == RATING_UNSET
|
||||
? new StarRating(maxStars)
|
||||
: new StarRating(maxStars, starRating);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,12 @@
|
||||
package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/** A rating expressed as "thumbs up" or "thumbs down". */
|
||||
public final class ThumbRating extends Rating {
|
||||
@ -78,22 +73,16 @@ public final class ThumbRating extends Rating {
|
||||
|
||||
private static final @RatingType int TYPE = RATING_TYPE_THUMB;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RATING_TYPE, FIELD_RATED, FIELD_IS_THUMBS_UP})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_RATED = 1;
|
||||
private static final int FIELD_IS_THUMBS_UP = 2;
|
||||
private static final String FIELD_RATED = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_IS_THUMBS_UP = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RATING_TYPE), TYPE);
|
||||
bundle.putBoolean(keyForField(FIELD_RATED), rated);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_THUMBS_UP), isThumbsUp);
|
||||
bundle.putInt(FIELD_RATING_TYPE, TYPE);
|
||||
bundle.putBoolean(FIELD_RATED, rated);
|
||||
bundle.putBoolean(FIELD_IS_THUMBS_UP, isThumbsUp);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -101,17 +90,10 @@ public final class ThumbRating extends Rating {
|
||||
@UnstableApi public static final Creator<ThumbRating> CREATOR = ThumbRating::fromBundle;
|
||||
|
||||
private static ThumbRating fromBundle(Bundle bundle) {
|
||||
checkArgument(
|
||||
bundle.getInt(keyForField(FIELD_RATING_TYPE), /* defaultValue= */ RATING_TYPE_UNSET)
|
||||
== TYPE);
|
||||
boolean rated = bundle.getBoolean(keyForField(FIELD_RATED), /* defaultValue= */ false);
|
||||
checkArgument(bundle.getInt(FIELD_RATING_TYPE, /* defaultValue= */ RATING_TYPE_UNSET) == TYPE);
|
||||
boolean rated = bundle.getBoolean(FIELD_RATED, /* defaultValue= */ false);
|
||||
return rated
|
||||
? new ThumbRating(
|
||||
bundle.getBoolean(keyForField(FIELD_IS_THUMBS_UP), /* defaultValue= */ false))
|
||||
? new ThumbRating(bundle.getBoolean(FIELD_IS_THUMBS_UP, /* defaultValue= */ false))
|
||||
: new ThumbRating();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,12 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkState;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.BundleUtil;
|
||||
@ -36,10 +34,6 @@ import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import com.google.errorprone.annotations.InlineMe;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -420,39 +414,20 @@ public abstract class Timeline implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_MEDIA_ITEM,
|
||||
FIELD_PRESENTATION_START_TIME_MS,
|
||||
FIELD_WINDOW_START_TIME_MS,
|
||||
FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS,
|
||||
FIELD_IS_SEEKABLE,
|
||||
FIELD_IS_DYNAMIC,
|
||||
FIELD_LIVE_CONFIGURATION,
|
||||
FIELD_IS_PLACEHOLDER,
|
||||
FIELD_DEFAULT_POSITION_US,
|
||||
FIELD_DURATION_US,
|
||||
FIELD_FIRST_PERIOD_INDEX,
|
||||
FIELD_LAST_PERIOD_INDEX,
|
||||
FIELD_POSITION_IN_FIRST_PERIOD_US,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_MEDIA_ITEM = 1;
|
||||
private static final int FIELD_PRESENTATION_START_TIME_MS = 2;
|
||||
private static final int FIELD_WINDOW_START_TIME_MS = 3;
|
||||
private static final int FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS = 4;
|
||||
private static final int FIELD_IS_SEEKABLE = 5;
|
||||
private static final int FIELD_IS_DYNAMIC = 6;
|
||||
private static final int FIELD_LIVE_CONFIGURATION = 7;
|
||||
private static final int FIELD_IS_PLACEHOLDER = 8;
|
||||
private static final int FIELD_DEFAULT_POSITION_US = 9;
|
||||
private static final int FIELD_DURATION_US = 10;
|
||||
private static final int FIELD_FIRST_PERIOD_INDEX = 11;
|
||||
private static final int FIELD_LAST_PERIOD_INDEX = 12;
|
||||
private static final int FIELD_POSITION_IN_FIRST_PERIOD_US = 13;
|
||||
private static final String FIELD_MEDIA_ITEM = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_PRESENTATION_START_TIME_MS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_WINDOW_START_TIME_MS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS =
|
||||
Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_IS_SEEKABLE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_IS_DYNAMIC = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_LIVE_CONFIGURATION = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_IS_PLACEHOLDER = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_DEFAULT_POSITION_US = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_DURATION_US = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_FIRST_PERIOD_INDEX = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_LAST_PERIOD_INDEX = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_POSITION_IN_FIRST_PERIOD_US = Util.intToStringMaxRadix(13);
|
||||
|
||||
/**
|
||||
* Returns a {@link Bundle} representing the information stored in this object.
|
||||
@ -467,46 +442,45 @@ public abstract class Timeline implements Bundleable {
|
||||
public Bundle toBundle(boolean excludeMediaItem) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (!excludeMediaItem) {
|
||||
bundle.putBundle(keyForField(FIELD_MEDIA_ITEM), mediaItem.toBundle());
|
||||
bundle.putBundle(FIELD_MEDIA_ITEM, mediaItem.toBundle());
|
||||
}
|
||||
if (presentationStartTimeMs != C.TIME_UNSET) {
|
||||
bundle.putLong(keyForField(FIELD_PRESENTATION_START_TIME_MS), presentationStartTimeMs);
|
||||
bundle.putLong(FIELD_PRESENTATION_START_TIME_MS, presentationStartTimeMs);
|
||||
}
|
||||
if (windowStartTimeMs != C.TIME_UNSET) {
|
||||
bundle.putLong(keyForField(FIELD_WINDOW_START_TIME_MS), windowStartTimeMs);
|
||||
bundle.putLong(FIELD_WINDOW_START_TIME_MS, windowStartTimeMs);
|
||||
}
|
||||
if (elapsedRealtimeEpochOffsetMs != C.TIME_UNSET) {
|
||||
bundle.putLong(
|
||||
keyForField(FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS), elapsedRealtimeEpochOffsetMs);
|
||||
bundle.putLong(FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS, elapsedRealtimeEpochOffsetMs);
|
||||
}
|
||||
if (isSeekable) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_SEEKABLE), isSeekable);
|
||||
bundle.putBoolean(FIELD_IS_SEEKABLE, isSeekable);
|
||||
}
|
||||
if (isDynamic) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_DYNAMIC), isDynamic);
|
||||
bundle.putBoolean(FIELD_IS_DYNAMIC, isDynamic);
|
||||
}
|
||||
|
||||
@Nullable MediaItem.LiveConfiguration liveConfiguration = this.liveConfiguration;
|
||||
if (liveConfiguration != null) {
|
||||
bundle.putBundle(keyForField(FIELD_LIVE_CONFIGURATION), liveConfiguration.toBundle());
|
||||
bundle.putBundle(FIELD_LIVE_CONFIGURATION, liveConfiguration.toBundle());
|
||||
}
|
||||
if (isPlaceholder) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLACEHOLDER), isPlaceholder);
|
||||
bundle.putBoolean(FIELD_IS_PLACEHOLDER, isPlaceholder);
|
||||
}
|
||||
if (defaultPositionUs != 0) {
|
||||
bundle.putLong(keyForField(FIELD_DEFAULT_POSITION_US), defaultPositionUs);
|
||||
bundle.putLong(FIELD_DEFAULT_POSITION_US, defaultPositionUs);
|
||||
}
|
||||
if (durationUs != C.TIME_UNSET) {
|
||||
bundle.putLong(keyForField(FIELD_DURATION_US), durationUs);
|
||||
bundle.putLong(FIELD_DURATION_US, durationUs);
|
||||
}
|
||||
if (firstPeriodIndex != 0) {
|
||||
bundle.putInt(keyForField(FIELD_FIRST_PERIOD_INDEX), firstPeriodIndex);
|
||||
bundle.putInt(FIELD_FIRST_PERIOD_INDEX, firstPeriodIndex);
|
||||
}
|
||||
if (lastPeriodIndex != 0) {
|
||||
bundle.putInt(keyForField(FIELD_LAST_PERIOD_INDEX), lastPeriodIndex);
|
||||
bundle.putInt(FIELD_LAST_PERIOD_INDEX, lastPeriodIndex);
|
||||
}
|
||||
if (positionInFirstPeriodUs != 0) {
|
||||
bundle.putLong(keyForField(FIELD_POSITION_IN_FIRST_PERIOD_US), positionInFirstPeriodUs);
|
||||
bundle.putLong(FIELD_POSITION_IN_FIRST_PERIOD_US, positionInFirstPeriodUs);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -534,42 +508,31 @@ public abstract class Timeline implements Bundleable {
|
||||
@UnstableApi public static final Creator<Window> CREATOR = Window::fromBundle;
|
||||
|
||||
private static Window fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle mediaItemBundle = bundle.getBundle(keyForField(FIELD_MEDIA_ITEM));
|
||||
@Nullable Bundle mediaItemBundle = bundle.getBundle(FIELD_MEDIA_ITEM);
|
||||
@Nullable
|
||||
MediaItem mediaItem =
|
||||
mediaItemBundle != null ? MediaItem.CREATOR.fromBundle(mediaItemBundle) : MediaItem.EMPTY;
|
||||
long presentationStartTimeMs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_PRESENTATION_START_TIME_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
bundle.getLong(FIELD_PRESENTATION_START_TIME_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long windowStartTimeMs =
|
||||
bundle.getLong(keyForField(FIELD_WINDOW_START_TIME_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
bundle.getLong(FIELD_WINDOW_START_TIME_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long elapsedRealtimeEpochOffsetMs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS),
|
||||
/* defaultValue= */ C.TIME_UNSET);
|
||||
boolean isSeekable =
|
||||
bundle.getBoolean(keyForField(FIELD_IS_SEEKABLE), /* defaultValue= */ false);
|
||||
boolean isDynamic =
|
||||
bundle.getBoolean(keyForField(FIELD_IS_DYNAMIC), /* defaultValue= */ false);
|
||||
@Nullable
|
||||
Bundle liveConfigurationBundle = bundle.getBundle(keyForField(FIELD_LIVE_CONFIGURATION));
|
||||
bundle.getLong(FIELD_ELAPSED_REALTIME_EPOCH_OFFSET_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
boolean isSeekable = bundle.getBoolean(FIELD_IS_SEEKABLE, /* defaultValue= */ false);
|
||||
boolean isDynamic = bundle.getBoolean(FIELD_IS_DYNAMIC, /* defaultValue= */ false);
|
||||
@Nullable Bundle liveConfigurationBundle = bundle.getBundle(FIELD_LIVE_CONFIGURATION);
|
||||
@Nullable
|
||||
MediaItem.LiveConfiguration liveConfiguration =
|
||||
liveConfigurationBundle != null
|
||||
? MediaItem.LiveConfiguration.CREATOR.fromBundle(liveConfigurationBundle)
|
||||
: null;
|
||||
boolean isPlaceHolder =
|
||||
bundle.getBoolean(keyForField(FIELD_IS_PLACEHOLDER), /* defaultValue= */ false);
|
||||
long defaultPositionUs =
|
||||
bundle.getLong(keyForField(FIELD_DEFAULT_POSITION_US), /* defaultValue= */ 0);
|
||||
long durationUs =
|
||||
bundle.getLong(keyForField(FIELD_DURATION_US), /* defaultValue= */ C.TIME_UNSET);
|
||||
int firstPeriodIndex =
|
||||
bundle.getInt(keyForField(FIELD_FIRST_PERIOD_INDEX), /* defaultValue= */ 0);
|
||||
int lastPeriodIndex =
|
||||
bundle.getInt(keyForField(FIELD_LAST_PERIOD_INDEX), /* defaultValue= */ 0);
|
||||
boolean isPlaceHolder = bundle.getBoolean(FIELD_IS_PLACEHOLDER, /* defaultValue= */ false);
|
||||
long defaultPositionUs = bundle.getLong(FIELD_DEFAULT_POSITION_US, /* defaultValue= */ 0);
|
||||
long durationUs = bundle.getLong(FIELD_DURATION_US, /* defaultValue= */ C.TIME_UNSET);
|
||||
int firstPeriodIndex = bundle.getInt(FIELD_FIRST_PERIOD_INDEX, /* defaultValue= */ 0);
|
||||
int lastPeriodIndex = bundle.getInt(FIELD_LAST_PERIOD_INDEX, /* defaultValue= */ 0);
|
||||
long positionInFirstPeriodUs =
|
||||
bundle.getLong(keyForField(FIELD_POSITION_IN_FIRST_PERIOD_US), /* defaultValue= */ 0);
|
||||
bundle.getLong(FIELD_POSITION_IN_FIRST_PERIOD_US, /* defaultValue= */ 0);
|
||||
|
||||
Window window = new Window();
|
||||
window.set(
|
||||
@ -590,10 +553,6 @@ public abstract class Timeline implements Bundleable {
|
||||
window.isPlaceholder = isPlaceHolder;
|
||||
return window;
|
||||
}
|
||||
|
||||
private static String keyForField(@Window.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -945,23 +904,11 @@ public abstract class Timeline implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_WINDOW_INDEX,
|
||||
FIELD_DURATION_US,
|
||||
FIELD_POSITION_IN_WINDOW_US,
|
||||
FIELD_PLACEHOLDER,
|
||||
FIELD_AD_PLAYBACK_STATE
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_WINDOW_INDEX = 0;
|
||||
private static final int FIELD_DURATION_US = 1;
|
||||
private static final int FIELD_POSITION_IN_WINDOW_US = 2;
|
||||
private static final int FIELD_PLACEHOLDER = 3;
|
||||
private static final int FIELD_AD_PLAYBACK_STATE = 4;
|
||||
private static final String FIELD_WINDOW_INDEX = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_DURATION_US = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_POSITION_IN_WINDOW_US = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_PLACEHOLDER = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_AD_PLAYBACK_STATE = Util.intToStringMaxRadix(4);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -974,19 +921,19 @@ public abstract class Timeline implements Bundleable {
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (windowIndex != 0) {
|
||||
bundle.putInt(keyForField(FIELD_WINDOW_INDEX), windowIndex);
|
||||
bundle.putInt(FIELD_WINDOW_INDEX, windowIndex);
|
||||
}
|
||||
if (durationUs != C.TIME_UNSET) {
|
||||
bundle.putLong(keyForField(FIELD_DURATION_US), durationUs);
|
||||
bundle.putLong(FIELD_DURATION_US, durationUs);
|
||||
}
|
||||
if (positionInWindowUs != 0) {
|
||||
bundle.putLong(keyForField(FIELD_POSITION_IN_WINDOW_US), positionInWindowUs);
|
||||
bundle.putLong(FIELD_POSITION_IN_WINDOW_US, positionInWindowUs);
|
||||
}
|
||||
if (isPlaceholder) {
|
||||
bundle.putBoolean(keyForField(FIELD_PLACEHOLDER), isPlaceholder);
|
||||
bundle.putBoolean(FIELD_PLACEHOLDER, isPlaceholder);
|
||||
}
|
||||
if (!adPlaybackState.equals(AdPlaybackState.NONE)) {
|
||||
bundle.putBundle(keyForField(FIELD_AD_PLAYBACK_STATE), adPlaybackState.toBundle());
|
||||
bundle.putBundle(FIELD_AD_PLAYBACK_STATE, adPlaybackState.toBundle());
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
@ -999,15 +946,11 @@ public abstract class Timeline implements Bundleable {
|
||||
@UnstableApi public static final Creator<Period> CREATOR = Period::fromBundle;
|
||||
|
||||
private static Period fromBundle(Bundle bundle) {
|
||||
int windowIndex = bundle.getInt(keyForField(FIELD_WINDOW_INDEX), /* defaultValue= */ 0);
|
||||
long durationUs =
|
||||
bundle.getLong(keyForField(FIELD_DURATION_US), /* defaultValue= */ C.TIME_UNSET);
|
||||
long positionInWindowUs =
|
||||
bundle.getLong(keyForField(FIELD_POSITION_IN_WINDOW_US), /* defaultValue= */ 0);
|
||||
boolean isPlaceholder =
|
||||
bundle.getBoolean(keyForField(FIELD_PLACEHOLDER), /* defaultValue= */ false);
|
||||
@Nullable
|
||||
Bundle adPlaybackStateBundle = bundle.getBundle(keyForField(FIELD_AD_PLAYBACK_STATE));
|
||||
int windowIndex = bundle.getInt(FIELD_WINDOW_INDEX, /* defaultValue= */ 0);
|
||||
long durationUs = bundle.getLong(FIELD_DURATION_US, /* defaultValue= */ C.TIME_UNSET);
|
||||
long positionInWindowUs = bundle.getLong(FIELD_POSITION_IN_WINDOW_US, /* defaultValue= */ 0);
|
||||
boolean isPlaceholder = bundle.getBoolean(FIELD_PLACEHOLDER, /* defaultValue= */ false);
|
||||
@Nullable Bundle adPlaybackStateBundle = bundle.getBundle(FIELD_AD_PLAYBACK_STATE);
|
||||
AdPlaybackState adPlaybackState =
|
||||
adPlaybackStateBundle != null
|
||||
? AdPlaybackState.CREATOR.fromBundle(adPlaybackStateBundle)
|
||||
@ -1024,10 +967,6 @@ public abstract class Timeline implements Bundleable {
|
||||
isPlaceholder);
|
||||
return period;
|
||||
}
|
||||
|
||||
private static String keyForField(@Period.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/** An empty timeline. */
|
||||
@ -1447,19 +1386,9 @@ public abstract class Timeline implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_WINDOWS,
|
||||
FIELD_PERIODS,
|
||||
FIELD_SHUFFLED_WINDOW_INDICES,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_WINDOWS = 0;
|
||||
private static final int FIELD_PERIODS = 1;
|
||||
private static final int FIELD_SHUFFLED_WINDOW_INDICES = 2;
|
||||
private static final String FIELD_WINDOWS = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_PERIODS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_SHUFFLED_WINDOW_INDICES = Util.intToStringMaxRadix(2);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -1499,11 +1428,9 @@ public abstract class Timeline implements Bundleable {
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
BundleUtil.putBinder(
|
||||
bundle, keyForField(FIELD_WINDOWS), new BundleListRetriever(windowBundles));
|
||||
BundleUtil.putBinder(
|
||||
bundle, keyForField(FIELD_PERIODS), new BundleListRetriever(periodBundles));
|
||||
bundle.putIntArray(keyForField(FIELD_SHUFFLED_WINDOW_INDICES), shuffledWindowIndices);
|
||||
BundleUtil.putBinder(bundle, FIELD_WINDOWS, new BundleListRetriever(windowBundles));
|
||||
BundleUtil.putBinder(bundle, FIELD_PERIODS, new BundleListRetriever(periodBundles));
|
||||
bundle.putIntArray(FIELD_SHUFFLED_WINDOW_INDICES, shuffledWindowIndices);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -1531,13 +1458,10 @@ public abstract class Timeline implements Bundleable {
|
||||
|
||||
private static Timeline fromBundle(Bundle bundle) {
|
||||
ImmutableList<Window> windows =
|
||||
fromBundleListRetriever(
|
||||
Window.CREATOR, BundleUtil.getBinder(bundle, keyForField(FIELD_WINDOWS)));
|
||||
fromBundleListRetriever(Window.CREATOR, BundleUtil.getBinder(bundle, FIELD_WINDOWS));
|
||||
ImmutableList<Period> periods =
|
||||
fromBundleListRetriever(
|
||||
Period.CREATOR, BundleUtil.getBinder(bundle, keyForField(FIELD_PERIODS)));
|
||||
@Nullable
|
||||
int[] shuffledWindowIndices = bundle.getIntArray(keyForField(FIELD_SHUFFLED_WINDOW_INDICES));
|
||||
fromBundleListRetriever(Period.CREATOR, BundleUtil.getBinder(bundle, FIELD_PERIODS));
|
||||
@Nullable int[] shuffledWindowIndices = bundle.getIntArray(FIELD_SHUFFLED_WINDOW_INDICES);
|
||||
return new RemotableTimeline(
|
||||
windows,
|
||||
periods,
|
||||
@ -1559,10 +1483,6 @@ public abstract class Timeline implements Bundleable {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
private static int[] generateUnshuffledIndices(int n) {
|
||||
int[] indices = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
@ -16,20 +16,15 @@
|
||||
package androidx.media3.common;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -165,15 +160,8 @@ public final class TrackGroup implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_FORMATS, FIELD_ID})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_FORMATS = 0;
|
||||
private static final int FIELD_ID = 1;
|
||||
private static final String FIELD_FORMATS = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_ID = Util.intToStringMaxRadix(1);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
@ -183,8 +171,8 @@ public final class TrackGroup implements Bundleable {
|
||||
for (Format format : formats) {
|
||||
arrayList.add(format.toBundle(/* excludeMetadata= */ true));
|
||||
}
|
||||
bundle.putParcelableArrayList(keyForField(FIELD_FORMATS), arrayList);
|
||||
bundle.putString(keyForField(FIELD_ID), id);
|
||||
bundle.putParcelableArrayList(FIELD_FORMATS, arrayList);
|
||||
bundle.putString(FIELD_ID, id);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -192,20 +180,15 @@ public final class TrackGroup implements Bundleable {
|
||||
@UnstableApi
|
||||
public static final Creator<TrackGroup> CREATOR =
|
||||
bundle -> {
|
||||
@Nullable
|
||||
List<Bundle> formatBundles = bundle.getParcelableArrayList(keyForField(FIELD_FORMATS));
|
||||
@Nullable List<Bundle> formatBundles = bundle.getParcelableArrayList(FIELD_FORMATS);
|
||||
List<Format> formats =
|
||||
formatBundles == null
|
||||
? ImmutableList.of()
|
||||
: BundleableUtil.fromBundleList(Format.CREATOR, formatBundles);
|
||||
String id = bundle.getString(keyForField(FIELD_ID), /* defaultValue= */ "");
|
||||
String id = bundle.getString(FIELD_ID, /* defaultValue= */ "");
|
||||
return new TrackGroup(id, formats.toArray(new Format[0]));
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
private void verifyCorrectness() {
|
||||
// TrackGroups should only contain tracks with exactly the same content (but in different
|
||||
// qualities). We only log an error instead of throwing to not break backwards-compatibility for
|
||||
|
@ -20,14 +20,11 @@ import static java.util.Collections.max;
|
||||
import static java.util.Collections.min;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -54,16 +51,8 @@ public final class TrackSelectionOverride implements Bundleable {
|
||||
/** The indices of tracks in a {@link TrackGroup} to be selected. */
|
||||
public final ImmutableList<Integer> trackIndices;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({
|
||||
FIELD_TRACK_GROUP,
|
||||
FIELD_TRACKS,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TRACK_GROUP = 0;
|
||||
private static final int FIELD_TRACKS = 1;
|
||||
private static final String FIELD_TRACK_GROUP = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_TRACKS = Util.intToStringMaxRadix(1);
|
||||
|
||||
/**
|
||||
* Constructs an instance to force {@code trackIndex} in {@code trackGroup} to be selected.
|
||||
@ -119,8 +108,8 @@ public final class TrackSelectionOverride implements Bundleable {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), mediaTrackGroup.toBundle());
|
||||
bundle.putIntArray(keyForField(FIELD_TRACKS), Ints.toArray(trackIndices));
|
||||
bundle.putBundle(FIELD_TRACK_GROUP, mediaTrackGroup.toBundle());
|
||||
bundle.putIntArray(FIELD_TRACKS, Ints.toArray(trackIndices));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -128,13 +117,9 @@ public final class TrackSelectionOverride implements Bundleable {
|
||||
@UnstableApi
|
||||
public static final Creator<TrackSelectionOverride> CREATOR =
|
||||
bundle -> {
|
||||
Bundle trackGroupBundle = checkNotNull(bundle.getBundle(keyForField(FIELD_TRACK_GROUP)));
|
||||
Bundle trackGroupBundle = checkNotNull(bundle.getBundle(FIELD_TRACK_GROUP));
|
||||
TrackGroup mediaTrackGroup = TrackGroup.CREATOR.fromBundle(trackGroupBundle);
|
||||
int[] tracks = checkNotNull(bundle.getIntArray(keyForField(FIELD_TRACKS)));
|
||||
int[] tracks = checkNotNull(bundle.getIntArray(FIELD_TRACKS));
|
||||
return new TrackSelectionOverride(mediaTrackGroup, Ints.asList(tracks));
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -158,95 +158,71 @@ public class TrackSelectionParameters implements Bundleable {
|
||||
@UnstableApi
|
||||
protected Builder(Bundle bundle) {
|
||||
// Video
|
||||
maxVideoWidth =
|
||||
bundle.getInt(keyForField(FIELD_MAX_VIDEO_WIDTH), DEFAULT_WITHOUT_CONTEXT.maxVideoWidth);
|
||||
maxVideoWidth = bundle.getInt(FIELD_MAX_VIDEO_WIDTH, DEFAULT_WITHOUT_CONTEXT.maxVideoWidth);
|
||||
maxVideoHeight =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MAX_VIDEO_HEIGHT), DEFAULT_WITHOUT_CONTEXT.maxVideoHeight);
|
||||
bundle.getInt(FIELD_MAX_VIDEO_HEIGHT, DEFAULT_WITHOUT_CONTEXT.maxVideoHeight);
|
||||
maxVideoFrameRate =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MAX_VIDEO_FRAMERATE), DEFAULT_WITHOUT_CONTEXT.maxVideoFrameRate);
|
||||
bundle.getInt(FIELD_MAX_VIDEO_FRAMERATE, DEFAULT_WITHOUT_CONTEXT.maxVideoFrameRate);
|
||||
maxVideoBitrate =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MAX_VIDEO_BITRATE), DEFAULT_WITHOUT_CONTEXT.maxVideoBitrate);
|
||||
minVideoWidth =
|
||||
bundle.getInt(keyForField(FIELD_MIN_VIDEO_WIDTH), DEFAULT_WITHOUT_CONTEXT.minVideoWidth);
|
||||
bundle.getInt(FIELD_MAX_VIDEO_BITRATE, DEFAULT_WITHOUT_CONTEXT.maxVideoBitrate);
|
||||
minVideoWidth = bundle.getInt(FIELD_MIN_VIDEO_WIDTH, DEFAULT_WITHOUT_CONTEXT.minVideoWidth);
|
||||
minVideoHeight =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MIN_VIDEO_HEIGHT), DEFAULT_WITHOUT_CONTEXT.minVideoHeight);
|
||||
bundle.getInt(FIELD_MIN_VIDEO_HEIGHT, DEFAULT_WITHOUT_CONTEXT.minVideoHeight);
|
||||
minVideoFrameRate =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MIN_VIDEO_FRAMERATE), DEFAULT_WITHOUT_CONTEXT.minVideoFrameRate);
|
||||
bundle.getInt(FIELD_MIN_VIDEO_FRAMERATE, DEFAULT_WITHOUT_CONTEXT.minVideoFrameRate);
|
||||
minVideoBitrate =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MIN_VIDEO_BITRATE), DEFAULT_WITHOUT_CONTEXT.minVideoBitrate);
|
||||
viewportWidth =
|
||||
bundle.getInt(keyForField(FIELD_VIEWPORT_WIDTH), DEFAULT_WITHOUT_CONTEXT.viewportWidth);
|
||||
viewportHeight =
|
||||
bundle.getInt(keyForField(FIELD_VIEWPORT_HEIGHT), DEFAULT_WITHOUT_CONTEXT.viewportHeight);
|
||||
bundle.getInt(FIELD_MIN_VIDEO_BITRATE, DEFAULT_WITHOUT_CONTEXT.minVideoBitrate);
|
||||
viewportWidth = bundle.getInt(FIELD_VIEWPORT_WIDTH, DEFAULT_WITHOUT_CONTEXT.viewportWidth);
|
||||
viewportHeight = bundle.getInt(FIELD_VIEWPORT_HEIGHT, DEFAULT_WITHOUT_CONTEXT.viewportHeight);
|
||||
viewportOrientationMayChange =
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE),
|
||||
FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE,
|
||||
DEFAULT_WITHOUT_CONTEXT.viewportOrientationMayChange);
|
||||
preferredVideoMimeTypes =
|
||||
ImmutableList.copyOf(
|
||||
firstNonNull(
|
||||
bundle.getStringArray(keyForField(FIELD_PREFERRED_VIDEO_MIMETYPES)),
|
||||
new String[0]));
|
||||
firstNonNull(bundle.getStringArray(FIELD_PREFERRED_VIDEO_MIMETYPES), new String[0]));
|
||||
preferredVideoRoleFlags =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PREFERRED_VIDEO_ROLE_FLAGS),
|
||||
DEFAULT_WITHOUT_CONTEXT.preferredVideoRoleFlags);
|
||||
FIELD_PREFERRED_VIDEO_ROLE_FLAGS, DEFAULT_WITHOUT_CONTEXT.preferredVideoRoleFlags);
|
||||
// Audio
|
||||
String[] preferredAudioLanguages1 =
|
||||
firstNonNull(
|
||||
bundle.getStringArray(keyForField(FIELD_PREFERRED_AUDIO_LANGUAGES)), new String[0]);
|
||||
firstNonNull(bundle.getStringArray(FIELD_PREFERRED_AUDIO_LANGUAGES), new String[0]);
|
||||
preferredAudioLanguages = normalizeLanguageCodes(preferredAudioLanguages1);
|
||||
preferredAudioRoleFlags =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PREFERRED_AUDIO_ROLE_FLAGS),
|
||||
DEFAULT_WITHOUT_CONTEXT.preferredAudioRoleFlags);
|
||||
FIELD_PREFERRED_AUDIO_ROLE_FLAGS, DEFAULT_WITHOUT_CONTEXT.preferredAudioRoleFlags);
|
||||
maxAudioChannelCount =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MAX_AUDIO_CHANNEL_COUNT),
|
||||
DEFAULT_WITHOUT_CONTEXT.maxAudioChannelCount);
|
||||
FIELD_MAX_AUDIO_CHANNEL_COUNT, DEFAULT_WITHOUT_CONTEXT.maxAudioChannelCount);
|
||||
maxAudioBitrate =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MAX_AUDIO_BITRATE), DEFAULT_WITHOUT_CONTEXT.maxAudioBitrate);
|
||||
bundle.getInt(FIELD_MAX_AUDIO_BITRATE, DEFAULT_WITHOUT_CONTEXT.maxAudioBitrate);
|
||||
preferredAudioMimeTypes =
|
||||
ImmutableList.copyOf(
|
||||
firstNonNull(
|
||||
bundle.getStringArray(keyForField(FIELD_PREFERRED_AUDIO_MIME_TYPES)),
|
||||
new String[0]));
|
||||
firstNonNull(bundle.getStringArray(FIELD_PREFERRED_AUDIO_MIME_TYPES), new String[0]));
|
||||
// Text
|
||||
preferredTextLanguages =
|
||||
normalizeLanguageCodes(
|
||||
firstNonNull(
|
||||
bundle.getStringArray(keyForField(FIELD_PREFERRED_TEXT_LANGUAGES)),
|
||||
new String[0]));
|
||||
firstNonNull(bundle.getStringArray(FIELD_PREFERRED_TEXT_LANGUAGES), new String[0]));
|
||||
preferredTextRoleFlags =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PREFERRED_TEXT_ROLE_FLAGS),
|
||||
DEFAULT_WITHOUT_CONTEXT.preferredTextRoleFlags);
|
||||
FIELD_PREFERRED_TEXT_ROLE_FLAGS, DEFAULT_WITHOUT_CONTEXT.preferredTextRoleFlags);
|
||||
ignoredTextSelectionFlags =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_IGNORED_TEXT_SELECTION_FLAGS),
|
||||
FIELD_IGNORED_TEXT_SELECTION_FLAGS,
|
||||
DEFAULT_WITHOUT_CONTEXT.ignoredTextSelectionFlags);
|
||||
selectUndeterminedTextLanguage =
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE),
|
||||
FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE,
|
||||
DEFAULT_WITHOUT_CONTEXT.selectUndeterminedTextLanguage);
|
||||
// General
|
||||
forceLowestBitrate =
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_FORCE_LOWEST_BITRATE), DEFAULT_WITHOUT_CONTEXT.forceLowestBitrate);
|
||||
bundle.getBoolean(FIELD_FORCE_LOWEST_BITRATE, DEFAULT_WITHOUT_CONTEXT.forceLowestBitrate);
|
||||
forceHighestSupportedBitrate =
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE),
|
||||
FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE,
|
||||
DEFAULT_WITHOUT_CONTEXT.forceHighestSupportedBitrate);
|
||||
@Nullable
|
||||
List<Bundle> overrideBundleList =
|
||||
bundle.getParcelableArrayList(keyForField(FIELD_SELECTION_OVERRIDES));
|
||||
List<Bundle> overrideBundleList = bundle.getParcelableArrayList(FIELD_SELECTION_OVERRIDES);
|
||||
List<TrackSelectionOverride> overrideList =
|
||||
overrideBundleList == null
|
||||
? ImmutableList.of()
|
||||
@ -257,7 +233,7 @@ public class TrackSelectionParameters implements Bundleable {
|
||||
overrides.put(override.mediaTrackGroup, override);
|
||||
}
|
||||
int[] disabledTrackTypeArray =
|
||||
firstNonNull(bundle.getIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE)), new int[0]);
|
||||
firstNonNull(bundle.getIntArray(FIELD_DISABLED_TRACK_TYPE), new int[0]);
|
||||
disabledTrackTypes = new HashSet<>();
|
||||
for (@C.TrackType int disabledTrackType : disabledTrackTypeArray) {
|
||||
disabledTrackTypes.add(disabledTrackType);
|
||||
@ -1103,39 +1079,40 @@ public class TrackSelectionParameters implements Bundleable {
|
||||
|
||||
// Bundleable implementation
|
||||
|
||||
private static final int FIELD_PREFERRED_AUDIO_LANGUAGES = 1;
|
||||
private static final int FIELD_PREFERRED_AUDIO_ROLE_FLAGS = 2;
|
||||
private static final int FIELD_PREFERRED_TEXT_LANGUAGES = 3;
|
||||
private static final int FIELD_PREFERRED_TEXT_ROLE_FLAGS = 4;
|
||||
private static final int FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE = 5;
|
||||
private static final int FIELD_MAX_VIDEO_WIDTH = 6;
|
||||
private static final int FIELD_MAX_VIDEO_HEIGHT = 7;
|
||||
private static final int FIELD_MAX_VIDEO_FRAMERATE = 8;
|
||||
private static final int FIELD_MAX_VIDEO_BITRATE = 9;
|
||||
private static final int FIELD_MIN_VIDEO_WIDTH = 10;
|
||||
private static final int FIELD_MIN_VIDEO_HEIGHT = 11;
|
||||
private static final int FIELD_MIN_VIDEO_FRAMERATE = 12;
|
||||
private static final int FIELD_MIN_VIDEO_BITRATE = 13;
|
||||
private static final int FIELD_VIEWPORT_WIDTH = 14;
|
||||
private static final int FIELD_VIEWPORT_HEIGHT = 15;
|
||||
private static final int FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE = 16;
|
||||
private static final int FIELD_PREFERRED_VIDEO_MIMETYPES = 17;
|
||||
private static final int FIELD_MAX_AUDIO_CHANNEL_COUNT = 18;
|
||||
private static final int FIELD_MAX_AUDIO_BITRATE = 19;
|
||||
private static final int FIELD_PREFERRED_AUDIO_MIME_TYPES = 20;
|
||||
private static final int FIELD_FORCE_LOWEST_BITRATE = 21;
|
||||
private static final int FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE = 22;
|
||||
private static final int FIELD_SELECTION_OVERRIDES = 23;
|
||||
private static final int FIELD_DISABLED_TRACK_TYPE = 24;
|
||||
private static final int FIELD_PREFERRED_VIDEO_ROLE_FLAGS = 25;
|
||||
private static final int FIELD_IGNORED_TEXT_SELECTION_FLAGS = 26;
|
||||
private static final String FIELD_PREFERRED_AUDIO_LANGUAGES = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_PREFERRED_AUDIO_ROLE_FLAGS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_PREFERRED_TEXT_LANGUAGES = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_PREFERRED_TEXT_ROLE_FLAGS = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_MAX_VIDEO_WIDTH = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_MAX_VIDEO_HEIGHT = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_MAX_VIDEO_FRAMERATE = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_MAX_VIDEO_BITRATE = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_MIN_VIDEO_WIDTH = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_MIN_VIDEO_HEIGHT = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_MIN_VIDEO_FRAMERATE = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_MIN_VIDEO_BITRATE = Util.intToStringMaxRadix(13);
|
||||
private static final String FIELD_VIEWPORT_WIDTH = Util.intToStringMaxRadix(14);
|
||||
private static final String FIELD_VIEWPORT_HEIGHT = Util.intToStringMaxRadix(15);
|
||||
private static final String FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE = Util.intToStringMaxRadix(16);
|
||||
private static final String FIELD_PREFERRED_VIDEO_MIMETYPES = Util.intToStringMaxRadix(17);
|
||||
private static final String FIELD_MAX_AUDIO_CHANNEL_COUNT = Util.intToStringMaxRadix(18);
|
||||
private static final String FIELD_MAX_AUDIO_BITRATE = Util.intToStringMaxRadix(19);
|
||||
private static final String FIELD_PREFERRED_AUDIO_MIME_TYPES = Util.intToStringMaxRadix(20);
|
||||
private static final String FIELD_FORCE_LOWEST_BITRATE = Util.intToStringMaxRadix(21);
|
||||
private static final String FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE = Util.intToStringMaxRadix(22);
|
||||
private static final String FIELD_SELECTION_OVERRIDES = Util.intToStringMaxRadix(23);
|
||||
private static final String FIELD_DISABLED_TRACK_TYPE = Util.intToStringMaxRadix(24);
|
||||
private static final String FIELD_PREFERRED_VIDEO_ROLE_FLAGS = Util.intToStringMaxRadix(25);
|
||||
private static final String FIELD_IGNORED_TEXT_SELECTION_FLAGS = Util.intToStringMaxRadix(26);
|
||||
|
||||
/**
|
||||
* Defines a minimum field ID value for subclasses to use when implementing {@link #toBundle()}
|
||||
* and {@link Bundleable.Creator}.
|
||||
*
|
||||
* <p>Subclasses should obtain keys for their {@link Bundle} representation by applying a
|
||||
* non-negative offset on this constant and passing the result to {@link #keyForField(int)}.
|
||||
* non-negative offset on this constant and passing the result to {@link
|
||||
* Util#intToStringMaxRadix(int)}.
|
||||
*/
|
||||
@UnstableApi protected static final int FIELD_CUSTOM_ID_BASE = 1000;
|
||||
|
||||
@ -1144,46 +1121,39 @@ public class TrackSelectionParameters implements Bundleable {
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
// Video
|
||||
bundle.putInt(keyForField(FIELD_MAX_VIDEO_WIDTH), maxVideoWidth);
|
||||
bundle.putInt(keyForField(FIELD_MAX_VIDEO_HEIGHT), maxVideoHeight);
|
||||
bundle.putInt(keyForField(FIELD_MAX_VIDEO_FRAMERATE), maxVideoFrameRate);
|
||||
bundle.putInt(keyForField(FIELD_MAX_VIDEO_BITRATE), maxVideoBitrate);
|
||||
bundle.putInt(keyForField(FIELD_MIN_VIDEO_WIDTH), minVideoWidth);
|
||||
bundle.putInt(keyForField(FIELD_MIN_VIDEO_HEIGHT), minVideoHeight);
|
||||
bundle.putInt(keyForField(FIELD_MIN_VIDEO_FRAMERATE), minVideoFrameRate);
|
||||
bundle.putInt(keyForField(FIELD_MIN_VIDEO_BITRATE), minVideoBitrate);
|
||||
bundle.putInt(keyForField(FIELD_VIEWPORT_WIDTH), viewportWidth);
|
||||
bundle.putInt(keyForField(FIELD_VIEWPORT_HEIGHT), viewportHeight);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE), viewportOrientationMayChange);
|
||||
bundle.putInt(FIELD_MAX_VIDEO_WIDTH, maxVideoWidth);
|
||||
bundle.putInt(FIELD_MAX_VIDEO_HEIGHT, maxVideoHeight);
|
||||
bundle.putInt(FIELD_MAX_VIDEO_FRAMERATE, maxVideoFrameRate);
|
||||
bundle.putInt(FIELD_MAX_VIDEO_BITRATE, maxVideoBitrate);
|
||||
bundle.putInt(FIELD_MIN_VIDEO_WIDTH, minVideoWidth);
|
||||
bundle.putInt(FIELD_MIN_VIDEO_HEIGHT, minVideoHeight);
|
||||
bundle.putInt(FIELD_MIN_VIDEO_FRAMERATE, minVideoFrameRate);
|
||||
bundle.putInt(FIELD_MIN_VIDEO_BITRATE, minVideoBitrate);
|
||||
bundle.putInt(FIELD_VIEWPORT_WIDTH, viewportWidth);
|
||||
bundle.putInt(FIELD_VIEWPORT_HEIGHT, viewportHeight);
|
||||
bundle.putBoolean(FIELD_VIEWPORT_ORIENTATION_MAY_CHANGE, viewportOrientationMayChange);
|
||||
bundle.putStringArray(
|
||||
keyForField(FIELD_PREFERRED_VIDEO_MIMETYPES),
|
||||
preferredVideoMimeTypes.toArray(new String[0]));
|
||||
bundle.putInt(keyForField(FIELD_PREFERRED_VIDEO_ROLE_FLAGS), preferredVideoRoleFlags);
|
||||
FIELD_PREFERRED_VIDEO_MIMETYPES, preferredVideoMimeTypes.toArray(new String[0]));
|
||||
bundle.putInt(FIELD_PREFERRED_VIDEO_ROLE_FLAGS, preferredVideoRoleFlags);
|
||||
// Audio
|
||||
bundle.putStringArray(
|
||||
keyForField(FIELD_PREFERRED_AUDIO_LANGUAGES),
|
||||
preferredAudioLanguages.toArray(new String[0]));
|
||||
bundle.putInt(keyForField(FIELD_PREFERRED_AUDIO_ROLE_FLAGS), preferredAudioRoleFlags);
|
||||
bundle.putInt(keyForField(FIELD_MAX_AUDIO_CHANNEL_COUNT), maxAudioChannelCount);
|
||||
bundle.putInt(keyForField(FIELD_MAX_AUDIO_BITRATE), maxAudioBitrate);
|
||||
FIELD_PREFERRED_AUDIO_LANGUAGES, preferredAudioLanguages.toArray(new String[0]));
|
||||
bundle.putInt(FIELD_PREFERRED_AUDIO_ROLE_FLAGS, preferredAudioRoleFlags);
|
||||
bundle.putInt(FIELD_MAX_AUDIO_CHANNEL_COUNT, maxAudioChannelCount);
|
||||
bundle.putInt(FIELD_MAX_AUDIO_BITRATE, maxAudioBitrate);
|
||||
bundle.putStringArray(
|
||||
keyForField(FIELD_PREFERRED_AUDIO_MIME_TYPES),
|
||||
preferredAudioMimeTypes.toArray(new String[0]));
|
||||
FIELD_PREFERRED_AUDIO_MIME_TYPES, preferredAudioMimeTypes.toArray(new String[0]));
|
||||
// Text
|
||||
bundle.putStringArray(
|
||||
keyForField(FIELD_PREFERRED_TEXT_LANGUAGES), preferredTextLanguages.toArray(new String[0]));
|
||||
bundle.putInt(keyForField(FIELD_PREFERRED_TEXT_ROLE_FLAGS), preferredTextRoleFlags);
|
||||
bundle.putInt(keyForField(FIELD_IGNORED_TEXT_SELECTION_FLAGS), ignoredTextSelectionFlags);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE), selectUndeterminedTextLanguage);
|
||||
FIELD_PREFERRED_TEXT_LANGUAGES, preferredTextLanguages.toArray(new String[0]));
|
||||
bundle.putInt(FIELD_PREFERRED_TEXT_ROLE_FLAGS, preferredTextRoleFlags);
|
||||
bundle.putInt(FIELD_IGNORED_TEXT_SELECTION_FLAGS, ignoredTextSelectionFlags);
|
||||
bundle.putBoolean(FIELD_SELECT_UNDETERMINED_TEXT_LANGUAGE, selectUndeterminedTextLanguage);
|
||||
// General
|
||||
bundle.putBoolean(keyForField(FIELD_FORCE_LOWEST_BITRATE), forceLowestBitrate);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE), forceHighestSupportedBitrate);
|
||||
bundle.putParcelableArrayList(
|
||||
keyForField(FIELD_SELECTION_OVERRIDES), toBundleArrayList(overrides.values()));
|
||||
bundle.putIntArray(keyForField(FIELD_DISABLED_TRACK_TYPE), Ints.toArray(disabledTrackTypes));
|
||||
bundle.putBoolean(FIELD_FORCE_LOWEST_BITRATE, forceLowestBitrate);
|
||||
bundle.putBoolean(FIELD_FORCE_HIGHEST_SUPPORTED_BITRATE, forceHighestSupportedBitrate);
|
||||
bundle.putParcelableArrayList(FIELD_SELECTION_OVERRIDES, toBundleArrayList(overrides.values()));
|
||||
bundle.putIntArray(FIELD_DISABLED_TRACK_TYPE, Ints.toArray(disabledTrackTypes));
|
||||
|
||||
return bundle;
|
||||
}
|
||||
@ -1199,16 +1169,4 @@ public class TrackSelectionParameters implements Bundleable {
|
||||
@UnstableApi @Deprecated
|
||||
public static final Creator<TrackSelectionParameters> CREATOR =
|
||||
TrackSelectionParameters::fromBundle;
|
||||
|
||||
/**
|
||||
* Converts the given field number to a string which can be used as a field key when implementing
|
||||
* {@link #toBundle()} and {@link Bundleable.Creator}.
|
||||
*
|
||||
* <p>Subclasses should use {@code field} values greater than or equal to {@link
|
||||
* #FIELD_CUSTOM_ID_BASE}.
|
||||
*/
|
||||
@UnstableApi
|
||||
protected static String keyForField(int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -18,20 +18,15 @@ package androidx.media3.common;
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.BundleableUtil.toBundleArrayList;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Booleans;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -221,29 +216,19 @@ public final class Tracks implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TRACK_GROUP,
|
||||
FIELD_TRACK_SUPPORT,
|
||||
FIELD_TRACK_SELECTED,
|
||||
FIELD_ADAPTIVE_SUPPORTED,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TRACK_GROUP = 0;
|
||||
private static final int FIELD_TRACK_SUPPORT = 1;
|
||||
private static final int FIELD_TRACK_SELECTED = 3;
|
||||
private static final int FIELD_ADAPTIVE_SUPPORTED = 4;
|
||||
private static final String FIELD_TRACK_GROUP = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_TRACK_SUPPORT = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_TRACK_SELECTED = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_ADAPTIVE_SUPPORTED = Util.intToStringMaxRadix(4);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBundle(keyForField(FIELD_TRACK_GROUP), mediaTrackGroup.toBundle());
|
||||
bundle.putIntArray(keyForField(FIELD_TRACK_SUPPORT), trackSupport);
|
||||
bundle.putBooleanArray(keyForField(FIELD_TRACK_SELECTED), trackSelected);
|
||||
bundle.putBoolean(keyForField(FIELD_ADAPTIVE_SUPPORTED), adaptiveSupported);
|
||||
bundle.putBundle(FIELD_TRACK_GROUP, mediaTrackGroup.toBundle());
|
||||
bundle.putIntArray(FIELD_TRACK_SUPPORT, trackSupport);
|
||||
bundle.putBooleanArray(FIELD_TRACK_SELECTED, trackSelected);
|
||||
bundle.putBoolean(FIELD_ADAPTIVE_SUPPORTED, adaptiveSupported);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -253,23 +238,16 @@ public final class Tracks implements Bundleable {
|
||||
bundle -> {
|
||||
// Can't create a Tracks.Group without a TrackGroup
|
||||
TrackGroup trackGroup =
|
||||
TrackGroup.CREATOR.fromBundle(
|
||||
checkNotNull(bundle.getBundle(keyForField(FIELD_TRACK_GROUP))));
|
||||
TrackGroup.CREATOR.fromBundle(checkNotNull(bundle.getBundle(FIELD_TRACK_GROUP)));
|
||||
final @C.FormatSupport int[] trackSupport =
|
||||
MoreObjects.firstNonNull(
|
||||
bundle.getIntArray(keyForField(FIELD_TRACK_SUPPORT)), new int[trackGroup.length]);
|
||||
bundle.getIntArray(FIELD_TRACK_SUPPORT), new int[trackGroup.length]);
|
||||
boolean[] selected =
|
||||
MoreObjects.firstNonNull(
|
||||
bundle.getBooleanArray(keyForField(FIELD_TRACK_SELECTED)),
|
||||
new boolean[trackGroup.length]);
|
||||
boolean adaptiveSupported =
|
||||
bundle.getBoolean(keyForField(FIELD_ADAPTIVE_SUPPORTED), false);
|
||||
bundle.getBooleanArray(FIELD_TRACK_SELECTED), new boolean[trackGroup.length]);
|
||||
boolean adaptiveSupported = bundle.getBoolean(FIELD_ADAPTIVE_SUPPORTED, false);
|
||||
return new Group(trackGroup, adaptiveSupported, trackSupport, selected);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/** Empty tracks. */
|
||||
@ -385,21 +363,13 @@ public final class Tracks implements Bundleable {
|
||||
}
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TRACK_GROUPS,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TRACK_GROUPS = 0;
|
||||
private static final String FIELD_TRACK_GROUPS = Util.intToStringMaxRadix(0);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList(keyForField(FIELD_TRACK_GROUPS), toBundleArrayList(groups));
|
||||
bundle.putParcelableArrayList(FIELD_TRACK_GROUPS, toBundleArrayList(groups));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -407,16 +377,11 @@ public final class Tracks implements Bundleable {
|
||||
@UnstableApi
|
||||
public static final Creator<Tracks> CREATOR =
|
||||
bundle -> {
|
||||
@Nullable
|
||||
List<Bundle> groupBundles = bundle.getParcelableArrayList(keyForField(FIELD_TRACK_GROUPS));
|
||||
@Nullable List<Bundle> groupBundles = bundle.getParcelableArrayList(FIELD_TRACK_GROUPS);
|
||||
List<Group> groups =
|
||||
groupBundles == null
|
||||
? ImmutableList.of()
|
||||
: BundleableUtil.fromBundleList(Group.CREATOR, groupBundles);
|
||||
return new Tracks(groups);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -15,18 +15,12 @@
|
||||
*/
|
||||
package androidx.media3.common;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import androidx.media3.common.util.Util;
|
||||
|
||||
/** Represents the video size. */
|
||||
public final class VideoSize implements Bundleable {
|
||||
@ -132,48 +126,32 @@ public final class VideoSize implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_WIDTH,
|
||||
FIELD_HEIGHT,
|
||||
FIELD_UNAPPLIED_ROTATION_DEGREES,
|
||||
FIELD_PIXEL_WIDTH_HEIGHT_RATIO,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_WIDTH = 0;
|
||||
private static final int FIELD_HEIGHT = 1;
|
||||
private static final int FIELD_UNAPPLIED_ROTATION_DEGREES = 2;
|
||||
private static final int FIELD_PIXEL_WIDTH_HEIGHT_RATIO = 3;
|
||||
private static final String FIELD_WIDTH = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_HEIGHT = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_UNAPPLIED_ROTATION_DEGREES = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_PIXEL_WIDTH_HEIGHT_RATIO = Util.intToStringMaxRadix(3);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_WIDTH), width);
|
||||
bundle.putInt(keyForField(FIELD_HEIGHT), height);
|
||||
bundle.putInt(keyForField(FIELD_UNAPPLIED_ROTATION_DEGREES), unappliedRotationDegrees);
|
||||
bundle.putFloat(keyForField(FIELD_PIXEL_WIDTH_HEIGHT_RATIO), pixelWidthHeightRatio);
|
||||
bundle.putInt(FIELD_WIDTH, width);
|
||||
bundle.putInt(FIELD_HEIGHT, height);
|
||||
bundle.putInt(FIELD_UNAPPLIED_ROTATION_DEGREES, unappliedRotationDegrees);
|
||||
bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@UnstableApi
|
||||
public static final Creator<VideoSize> CREATOR =
|
||||
bundle -> {
|
||||
int width = bundle.getInt(keyForField(FIELD_WIDTH), DEFAULT_WIDTH);
|
||||
int height = bundle.getInt(keyForField(FIELD_HEIGHT), DEFAULT_HEIGHT);
|
||||
int width = bundle.getInt(FIELD_WIDTH, DEFAULT_WIDTH);
|
||||
int height = bundle.getInt(FIELD_HEIGHT, DEFAULT_HEIGHT);
|
||||
int unappliedRotationDegrees =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_UNAPPLIED_ROTATION_DEGREES), DEFAULT_UNAPPLIED_ROTATION_DEGREES);
|
||||
bundle.getInt(FIELD_UNAPPLIED_ROTATION_DEGREES, DEFAULT_UNAPPLIED_ROTATION_DEGREES);
|
||||
float pixelWidthHeightRatio =
|
||||
bundle.getFloat(
|
||||
keyForField(FIELD_PIXEL_WIDTH_HEIGHT_RATIO), DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO);
|
||||
bundle.getFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO);
|
||||
return new VideoSize(width, height, unappliedRotationDegrees, pixelWidthHeightRatio);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
@ -977,69 +978,45 @@ public final class Cue implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TEXT,
|
||||
FIELD_TEXT_ALIGNMENT,
|
||||
FIELD_MULTI_ROW_ALIGNMENT,
|
||||
FIELD_BITMAP,
|
||||
FIELD_LINE,
|
||||
FIELD_LINE_TYPE,
|
||||
FIELD_LINE_ANCHOR,
|
||||
FIELD_POSITION,
|
||||
FIELD_POSITION_ANCHOR,
|
||||
FIELD_TEXT_SIZE_TYPE,
|
||||
FIELD_TEXT_SIZE,
|
||||
FIELD_SIZE,
|
||||
FIELD_BITMAP_HEIGHT,
|
||||
FIELD_WINDOW_COLOR,
|
||||
FIELD_WINDOW_COLOR_SET,
|
||||
FIELD_VERTICAL_TYPE,
|
||||
FIELD_SHEAR_DEGREES
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TEXT = 0;
|
||||
private static final int FIELD_TEXT_ALIGNMENT = 1;
|
||||
private static final int FIELD_MULTI_ROW_ALIGNMENT = 2;
|
||||
private static final int FIELD_BITMAP = 3;
|
||||
private static final int FIELD_LINE = 4;
|
||||
private static final int FIELD_LINE_TYPE = 5;
|
||||
private static final int FIELD_LINE_ANCHOR = 6;
|
||||
private static final int FIELD_POSITION = 7;
|
||||
private static final int FIELD_POSITION_ANCHOR = 8;
|
||||
private static final int FIELD_TEXT_SIZE_TYPE = 9;
|
||||
private static final int FIELD_TEXT_SIZE = 10;
|
||||
private static final int FIELD_SIZE = 11;
|
||||
private static final int FIELD_BITMAP_HEIGHT = 12;
|
||||
private static final int FIELD_WINDOW_COLOR = 13;
|
||||
private static final int FIELD_WINDOW_COLOR_SET = 14;
|
||||
private static final int FIELD_VERTICAL_TYPE = 15;
|
||||
private static final int FIELD_SHEAR_DEGREES = 16;
|
||||
private static final String FIELD_TEXT = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_TEXT_ALIGNMENT = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_MULTI_ROW_ALIGNMENT = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_BITMAP = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_LINE = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_LINE_TYPE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_LINE_ANCHOR = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_POSITION = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_POSITION_ANCHOR = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_TEXT_SIZE_TYPE = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_TEXT_SIZE = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_SIZE = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_BITMAP_HEIGHT = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_WINDOW_COLOR = Util.intToStringMaxRadix(13);
|
||||
private static final String FIELD_WINDOW_COLOR_SET = Util.intToStringMaxRadix(14);
|
||||
private static final String FIELD_VERTICAL_TYPE = Util.intToStringMaxRadix(15);
|
||||
private static final String FIELD_SHEAR_DEGREES = Util.intToStringMaxRadix(16);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putCharSequence(keyForField(FIELD_TEXT), text);
|
||||
bundle.putSerializable(keyForField(FIELD_TEXT_ALIGNMENT), textAlignment);
|
||||
bundle.putSerializable(keyForField(FIELD_MULTI_ROW_ALIGNMENT), multiRowAlignment);
|
||||
bundle.putParcelable(keyForField(FIELD_BITMAP), bitmap);
|
||||
bundle.putFloat(keyForField(FIELD_LINE), line);
|
||||
bundle.putInt(keyForField(FIELD_LINE_TYPE), lineType);
|
||||
bundle.putInt(keyForField(FIELD_LINE_ANCHOR), lineAnchor);
|
||||
bundle.putFloat(keyForField(FIELD_POSITION), position);
|
||||
bundle.putInt(keyForField(FIELD_POSITION_ANCHOR), positionAnchor);
|
||||
bundle.putInt(keyForField(FIELD_TEXT_SIZE_TYPE), textSizeType);
|
||||
bundle.putFloat(keyForField(FIELD_TEXT_SIZE), textSize);
|
||||
bundle.putFloat(keyForField(FIELD_SIZE), size);
|
||||
bundle.putFloat(keyForField(FIELD_BITMAP_HEIGHT), bitmapHeight);
|
||||
bundle.putBoolean(keyForField(FIELD_WINDOW_COLOR_SET), windowColorSet);
|
||||
bundle.putInt(keyForField(FIELD_WINDOW_COLOR), windowColor);
|
||||
bundle.putInt(keyForField(FIELD_VERTICAL_TYPE), verticalType);
|
||||
bundle.putFloat(keyForField(FIELD_SHEAR_DEGREES), shearDegrees);
|
||||
bundle.putCharSequence(FIELD_TEXT, text);
|
||||
bundle.putSerializable(FIELD_TEXT_ALIGNMENT, textAlignment);
|
||||
bundle.putSerializable(FIELD_MULTI_ROW_ALIGNMENT, multiRowAlignment);
|
||||
bundle.putParcelable(FIELD_BITMAP, bitmap);
|
||||
bundle.putFloat(FIELD_LINE, line);
|
||||
bundle.putInt(FIELD_LINE_TYPE, lineType);
|
||||
bundle.putInt(FIELD_LINE_ANCHOR, lineAnchor);
|
||||
bundle.putFloat(FIELD_POSITION, position);
|
||||
bundle.putInt(FIELD_POSITION_ANCHOR, positionAnchor);
|
||||
bundle.putInt(FIELD_TEXT_SIZE_TYPE, textSizeType);
|
||||
bundle.putFloat(FIELD_TEXT_SIZE, textSize);
|
||||
bundle.putFloat(FIELD_SIZE, size);
|
||||
bundle.putFloat(FIELD_BITMAP_HEIGHT, bitmapHeight);
|
||||
bundle.putBoolean(FIELD_WINDOW_COLOR_SET, windowColorSet);
|
||||
bundle.putInt(FIELD_WINDOW_COLOR, windowColor);
|
||||
bundle.putInt(FIELD_VERTICAL_TYPE, verticalType);
|
||||
bundle.putFloat(FIELD_SHEAR_DEGREES, shearDegrees);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -1047,67 +1024,56 @@ public final class Cue implements Bundleable {
|
||||
|
||||
private static final Cue fromBundle(Bundle bundle) {
|
||||
Builder builder = new Builder();
|
||||
@Nullable CharSequence text = bundle.getCharSequence(keyForField(FIELD_TEXT));
|
||||
@Nullable CharSequence text = bundle.getCharSequence(FIELD_TEXT);
|
||||
if (text != null) {
|
||||
builder.setText(text);
|
||||
}
|
||||
@Nullable
|
||||
Alignment textAlignment = (Alignment) bundle.getSerializable(keyForField(FIELD_TEXT_ALIGNMENT));
|
||||
@Nullable Alignment textAlignment = (Alignment) bundle.getSerializable(FIELD_TEXT_ALIGNMENT);
|
||||
if (textAlignment != null) {
|
||||
builder.setTextAlignment(textAlignment);
|
||||
}
|
||||
@Nullable
|
||||
Alignment multiRowAlignment =
|
||||
(Alignment) bundle.getSerializable(keyForField(FIELD_MULTI_ROW_ALIGNMENT));
|
||||
Alignment multiRowAlignment = (Alignment) bundle.getSerializable(FIELD_MULTI_ROW_ALIGNMENT);
|
||||
if (multiRowAlignment != null) {
|
||||
builder.setMultiRowAlignment(multiRowAlignment);
|
||||
}
|
||||
@Nullable Bitmap bitmap = bundle.getParcelable(keyForField(FIELD_BITMAP));
|
||||
@Nullable Bitmap bitmap = bundle.getParcelable(FIELD_BITMAP);
|
||||
if (bitmap != null) {
|
||||
builder.setBitmap(bitmap);
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_LINE))
|
||||
&& bundle.containsKey(keyForField(FIELD_LINE_TYPE))) {
|
||||
builder.setLine(
|
||||
bundle.getFloat(keyForField(FIELD_LINE)), bundle.getInt(keyForField(FIELD_LINE_TYPE)));
|
||||
if (bundle.containsKey(FIELD_LINE) && bundle.containsKey(FIELD_LINE_TYPE)) {
|
||||
builder.setLine(bundle.getFloat(FIELD_LINE), bundle.getInt(FIELD_LINE_TYPE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_LINE_ANCHOR))) {
|
||||
builder.setLineAnchor(bundle.getInt(keyForField(FIELD_LINE_ANCHOR)));
|
||||
if (bundle.containsKey(FIELD_LINE_ANCHOR)) {
|
||||
builder.setLineAnchor(bundle.getInt(FIELD_LINE_ANCHOR));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_POSITION))) {
|
||||
builder.setPosition(bundle.getFloat(keyForField(FIELD_POSITION)));
|
||||
if (bundle.containsKey(FIELD_POSITION)) {
|
||||
builder.setPosition(bundle.getFloat(FIELD_POSITION));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_POSITION_ANCHOR))) {
|
||||
builder.setPositionAnchor(bundle.getInt(keyForField(FIELD_POSITION_ANCHOR)));
|
||||
if (bundle.containsKey(FIELD_POSITION_ANCHOR)) {
|
||||
builder.setPositionAnchor(bundle.getInt(FIELD_POSITION_ANCHOR));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_TEXT_SIZE))
|
||||
&& bundle.containsKey(keyForField(FIELD_TEXT_SIZE_TYPE))) {
|
||||
builder.setTextSize(
|
||||
bundle.getFloat(keyForField(FIELD_TEXT_SIZE)),
|
||||
bundle.getInt(keyForField(FIELD_TEXT_SIZE_TYPE)));
|
||||
if (bundle.containsKey(FIELD_TEXT_SIZE) && bundle.containsKey(FIELD_TEXT_SIZE_TYPE)) {
|
||||
builder.setTextSize(bundle.getFloat(FIELD_TEXT_SIZE), bundle.getInt(FIELD_TEXT_SIZE_TYPE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_SIZE))) {
|
||||
builder.setSize(bundle.getFloat(keyForField(FIELD_SIZE)));
|
||||
if (bundle.containsKey(FIELD_SIZE)) {
|
||||
builder.setSize(bundle.getFloat(FIELD_SIZE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_BITMAP_HEIGHT))) {
|
||||
builder.setBitmapHeight(bundle.getFloat(keyForField(FIELD_BITMAP_HEIGHT)));
|
||||
if (bundle.containsKey(FIELD_BITMAP_HEIGHT)) {
|
||||
builder.setBitmapHeight(bundle.getFloat(FIELD_BITMAP_HEIGHT));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_WINDOW_COLOR))) {
|
||||
builder.setWindowColor(bundle.getInt(keyForField(FIELD_WINDOW_COLOR)));
|
||||
if (bundle.containsKey(FIELD_WINDOW_COLOR)) {
|
||||
builder.setWindowColor(bundle.getInt(FIELD_WINDOW_COLOR));
|
||||
}
|
||||
if (!bundle.getBoolean(keyForField(FIELD_WINDOW_COLOR_SET), /* defaultValue= */ false)) {
|
||||
if (!bundle.getBoolean(FIELD_WINDOW_COLOR_SET, /* defaultValue= */ false)) {
|
||||
builder.clearWindowColor();
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_VERTICAL_TYPE))) {
|
||||
builder.setVerticalType(bundle.getInt(keyForField(FIELD_VERTICAL_TYPE)));
|
||||
if (bundle.containsKey(FIELD_VERTICAL_TYPE)) {
|
||||
builder.setVerticalType(bundle.getInt(FIELD_VERTICAL_TYPE));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_SHEAR_DEGREES))) {
|
||||
builder.setShearDegrees(bundle.getFloat(keyForField(FIELD_SHEAR_DEGREES)));
|
||||
if (bundle.containsKey(FIELD_SHEAR_DEGREES)) {
|
||||
builder.setShearDegrees(bundle.getFloat(FIELD_SHEAR_DEGREES));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -15,21 +15,15 @@
|
||||
*/
|
||||
package androidx.media3.common.text;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -66,41 +60,31 @@ public final class CueGroup implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_CUES, FIELD_PRESENTATION_TIME_US})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_CUES = 0;
|
||||
private static final int FIELD_PRESENTATION_TIME_US = 1;
|
||||
private static final String FIELD_CUES = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_PRESENTATION_TIME_US = Util.intToStringMaxRadix(1);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList(
|
||||
keyForField(FIELD_CUES), BundleableUtil.toBundleArrayList(filterOutBitmapCues(cues)));
|
||||
bundle.putLong(keyForField(FIELD_PRESENTATION_TIME_US), presentationTimeUs);
|
||||
FIELD_CUES, BundleableUtil.toBundleArrayList(filterOutBitmapCues(cues)));
|
||||
bundle.putLong(FIELD_PRESENTATION_TIME_US, presentationTimeUs);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@UnstableApi public static final Creator<CueGroup> CREATOR = CueGroup::fromBundle;
|
||||
|
||||
private static final CueGroup fromBundle(Bundle bundle) {
|
||||
@Nullable ArrayList<Bundle> cueBundles = bundle.getParcelableArrayList(keyForField(FIELD_CUES));
|
||||
@Nullable ArrayList<Bundle> cueBundles = bundle.getParcelableArrayList(FIELD_CUES);
|
||||
List<Cue> cues =
|
||||
cueBundles == null
|
||||
? ImmutableList.of()
|
||||
: BundleableUtil.fromBundleList(Cue.CREATOR, cueBundles);
|
||||
long presentationTimeUs = bundle.getLong(keyForField(FIELD_PRESENTATION_TIME_US));
|
||||
long presentationTimeUs = bundle.getLong(FIELD_PRESENTATION_TIME_US);
|
||||
return new CueGroup(cues, presentationTimeUs);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out {@link Cue} objects containing {@link Bitmap}. It is used when transferring cues
|
||||
* between processes to prevent transferring too much data.
|
||||
|
@ -2884,6 +2884,16 @@ public final class Util {
|
||||
: resources.getDrawable(drawableRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the integer using radix value {@link Character#MAX_RADIX}.
|
||||
*
|
||||
* @param i An integer to be converted to String.
|
||||
*/
|
||||
@UnstableApi
|
||||
public static String intToStringMaxRadix(int i) {
|
||||
return Integer.toString(i, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getSystemProperty(String name) {
|
||||
try {
|
||||
|
@ -859,6 +859,8 @@ public class MediaItemTest {
|
||||
|
||||
@Test
|
||||
public void createMediaItemInstance_roundTripViaBundle_yieldsEqualInstance() {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putString("key", "value");
|
||||
// Creates instance by setting some non-default values
|
||||
MediaItem mediaItem =
|
||||
new MediaItem.Builder()
|
||||
@ -874,11 +876,14 @@ public class MediaItemTest {
|
||||
new RequestMetadata.Builder()
|
||||
.setMediaUri(Uri.parse("http://test.test"))
|
||||
.setSearchQuery("search")
|
||||
.setExtras(extras)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
MediaItem mediaItemFromBundle = MediaItem.CREATOR.fromBundle(mediaItem.toBundle());
|
||||
|
||||
assertThat(mediaItemFromBundle).isEqualTo(mediaItem);
|
||||
assertThat(mediaItemFromBundle.requestMetadata.extras)
|
||||
.isEqualTo(mediaItem.requestMetadata.extras);
|
||||
}
|
||||
}
|
||||
|
@ -250,17 +250,15 @@ public final class ExoPlaybackException extends PlaybackException {
|
||||
|
||||
private ExoPlaybackException(Bundle bundle) {
|
||||
super(bundle);
|
||||
type = bundle.getInt(keyForField(FIELD_TYPE), /* defaultValue= */ TYPE_UNEXPECTED);
|
||||
rendererName = bundle.getString(keyForField(FIELD_RENDERER_NAME));
|
||||
rendererIndex =
|
||||
bundle.getInt(keyForField(FIELD_RENDERER_INDEX), /* defaultValue= */ C.INDEX_UNSET);
|
||||
@Nullable Bundle rendererFormatBundle = bundle.getBundle(keyForField(FIELD_RENDERER_FORMAT));
|
||||
type = bundle.getInt(FIELD_TYPE, /* defaultValue= */ TYPE_UNEXPECTED);
|
||||
rendererName = bundle.getString(FIELD_RENDERER_NAME);
|
||||
rendererIndex = bundle.getInt(FIELD_RENDERER_INDEX, /* defaultValue= */ C.INDEX_UNSET);
|
||||
@Nullable Bundle rendererFormatBundle = bundle.getBundle(FIELD_RENDERER_FORMAT);
|
||||
rendererFormat =
|
||||
rendererFormatBundle == null ? null : Format.CREATOR.fromBundle(rendererFormatBundle);
|
||||
rendererFormatSupport =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_RENDERER_FORMAT_SUPPORT), /* defaultValue= */ C.FORMAT_HANDLED);
|
||||
isRecoverable = bundle.getBoolean(keyForField(FIELD_IS_RECOVERABLE), /* defaultValue= */ false);
|
||||
bundle.getInt(FIELD_RENDERER_FORMAT_SUPPORT, /* defaultValue= */ C.FORMAT_HANDLED);
|
||||
isRecoverable = bundle.getBoolean(FIELD_IS_RECOVERABLE, /* defaultValue= */ false);
|
||||
mediaPeriodId = null;
|
||||
}
|
||||
|
||||
@ -403,12 +401,17 @@ public final class ExoPlaybackException extends PlaybackException {
|
||||
@UnstableApi
|
||||
public static final Creator<ExoPlaybackException> CREATOR = ExoPlaybackException::new;
|
||||
|
||||
private static final int FIELD_TYPE = FIELD_CUSTOM_ID_BASE + 1;
|
||||
private static final int FIELD_RENDERER_NAME = FIELD_CUSTOM_ID_BASE + 2;
|
||||
private static final int FIELD_RENDERER_INDEX = FIELD_CUSTOM_ID_BASE + 3;
|
||||
private static final int FIELD_RENDERER_FORMAT = FIELD_CUSTOM_ID_BASE + 4;
|
||||
private static final int FIELD_RENDERER_FORMAT_SUPPORT = FIELD_CUSTOM_ID_BASE + 5;
|
||||
private static final int FIELD_IS_RECOVERABLE = FIELD_CUSTOM_ID_BASE + 6;
|
||||
private static final String FIELD_TYPE = Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 1);
|
||||
private static final String FIELD_RENDERER_NAME =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 2);
|
||||
private static final String FIELD_RENDERER_INDEX =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 3);
|
||||
private static final String FIELD_RENDERER_FORMAT =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 4);
|
||||
private static final String FIELD_RENDERER_FORMAT_SUPPORT =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 5);
|
||||
private static final String FIELD_IS_RECOVERABLE =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 6);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -420,14 +423,14 @@ public final class ExoPlaybackException extends PlaybackException {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = super.toBundle();
|
||||
bundle.putInt(keyForField(FIELD_TYPE), type);
|
||||
bundle.putString(keyForField(FIELD_RENDERER_NAME), rendererName);
|
||||
bundle.putInt(keyForField(FIELD_RENDERER_INDEX), rendererIndex);
|
||||
bundle.putInt(FIELD_TYPE, type);
|
||||
bundle.putString(FIELD_RENDERER_NAME, rendererName);
|
||||
bundle.putInt(FIELD_RENDERER_INDEX, rendererIndex);
|
||||
if (rendererFormat != null) {
|
||||
bundle.putBundle(keyForField(FIELD_RENDERER_FORMAT), rendererFormat.toBundle());
|
||||
bundle.putBundle(FIELD_RENDERER_FORMAT, rendererFormat.toBundle());
|
||||
}
|
||||
bundle.putInt(keyForField(FIELD_RENDERER_FORMAT_SUPPORT), rendererFormatSupport);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_RECOVERABLE), isRecoverable);
|
||||
bundle.putInt(FIELD_RENDERER_FORMAT_SUPPORT, rendererFormatSupport);
|
||||
bundle.putBoolean(FIELD_IS_RECOVERABLE, isRecoverable);
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
package androidx.media3.exoplayer.source;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.C;
|
||||
@ -26,11 +23,8 @@ import androidx.media3.common.TrackGroup;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -118,21 +112,13 @@ public final class TrackGroupArray implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_TRACK_GROUPS,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TRACK_GROUPS = 0;
|
||||
private static final String FIELD_TRACK_GROUPS = Util.intToStringMaxRadix(0);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList(
|
||||
keyForField(FIELD_TRACK_GROUPS), BundleableUtil.toBundleArrayList(trackGroups));
|
||||
FIELD_TRACK_GROUPS, BundleableUtil.toBundleArrayList(trackGroups));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -140,8 +126,7 @@ public final class TrackGroupArray implements Bundleable {
|
||||
public static final Creator<TrackGroupArray> CREATOR =
|
||||
bundle -> {
|
||||
@Nullable
|
||||
List<Bundle> trackGroupBundles =
|
||||
bundle.getParcelableArrayList(keyForField(FIELD_TRACK_GROUPS));
|
||||
List<Bundle> trackGroupBundles = bundle.getParcelableArrayList(FIELD_TRACK_GROUPS);
|
||||
if (trackGroupBundles == null) {
|
||||
return new TrackGroupArray();
|
||||
}
|
||||
@ -163,8 +148,4 @@ public final class TrackGroupArray implements Bundleable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -827,69 +827,62 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
// Video
|
||||
setExceedVideoConstraintsIfNecessary(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY),
|
||||
Parameters.FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY,
|
||||
defaultValue.exceedVideoConstraintsIfNecessary));
|
||||
setAllowVideoMixedMimeTypeAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS,
|
||||
defaultValue.allowVideoMixedMimeTypeAdaptiveness));
|
||||
setAllowVideoNonSeamlessAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS,
|
||||
defaultValue.allowVideoNonSeamlessAdaptiveness));
|
||||
setAllowVideoMixedDecoderSupportAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(
|
||||
Parameters.FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
|
||||
defaultValue.allowVideoMixedDecoderSupportAdaptiveness));
|
||||
// Audio
|
||||
setExceedAudioConstraintsIfNecessary(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY),
|
||||
Parameters.FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY,
|
||||
defaultValue.exceedAudioConstraintsIfNecessary));
|
||||
setAllowAudioMixedMimeTypeAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS,
|
||||
defaultValue.allowAudioMixedMimeTypeAdaptiveness));
|
||||
setAllowAudioMixedSampleRateAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS,
|
||||
defaultValue.allowAudioMixedSampleRateAdaptiveness));
|
||||
setAllowAudioMixedChannelCountAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS,
|
||||
defaultValue.allowAudioMixedChannelCountAdaptiveness));
|
||||
setAllowAudioMixedDecoderSupportAdaptiveness(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS),
|
||||
Parameters.FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
|
||||
defaultValue.allowAudioMixedDecoderSupportAdaptiveness));
|
||||
setConstrainAudioChannelCountToDeviceCapabilities(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(
|
||||
Parameters.FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES),
|
||||
Parameters.FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES,
|
||||
defaultValue.constrainAudioChannelCountToDeviceCapabilities));
|
||||
// General
|
||||
setExceedRendererCapabilitiesIfNecessary(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY),
|
||||
Parameters.FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY,
|
||||
defaultValue.exceedRendererCapabilitiesIfNecessary));
|
||||
setTunnelingEnabled(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_TUNNELING_ENABLED),
|
||||
defaultValue.tunnelingEnabled));
|
||||
bundle.getBoolean(Parameters.FIELD_TUNNELING_ENABLED, defaultValue.tunnelingEnabled));
|
||||
setAllowMultipleAdaptiveSelections(
|
||||
bundle.getBoolean(
|
||||
Parameters.keyForField(Parameters.FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS),
|
||||
Parameters.FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS,
|
||||
defaultValue.allowMultipleAdaptiveSelections));
|
||||
// Overrides
|
||||
selectionOverrides = new SparseArray<>();
|
||||
setSelectionOverridesFromBundle(bundle);
|
||||
rendererDisabledFlags =
|
||||
makeSparseBooleanArrayFromTrueKeys(
|
||||
bundle.getIntArray(
|
||||
Parameters.keyForField(Parameters.FIELD_RENDERER_DISABLED_INDICES)));
|
||||
bundle.getIntArray(Parameters.FIELD_RENDERER_DISABLED_INDICES));
|
||||
}
|
||||
|
||||
@CanIgnoreReturnValue
|
||||
@ -1571,20 +1564,17 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
private void setSelectionOverridesFromBundle(Bundle bundle) {
|
||||
@Nullable
|
||||
int[] rendererIndices =
|
||||
bundle.getIntArray(
|
||||
Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES_RENDERER_INDICES));
|
||||
bundle.getIntArray(Parameters.FIELD_SELECTION_OVERRIDES_RENDERER_INDICES);
|
||||
@Nullable
|
||||
ArrayList<Bundle> trackGroupArrayBundles =
|
||||
bundle.getParcelableArrayList(
|
||||
Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS));
|
||||
bundle.getParcelableArrayList(Parameters.FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS);
|
||||
List<TrackGroupArray> trackGroupArrays =
|
||||
trackGroupArrayBundles == null
|
||||
? ImmutableList.of()
|
||||
: BundleableUtil.fromBundleList(TrackGroupArray.CREATOR, trackGroupArrayBundles);
|
||||
@Nullable
|
||||
SparseArray<Bundle> selectionOverrideBundles =
|
||||
bundle.getSparseParcelableArray(
|
||||
Parameters.keyForField(Parameters.FIELD_SELECTION_OVERRIDES));
|
||||
bundle.getSparseParcelableArray(Parameters.FIELD_SELECTION_OVERRIDES);
|
||||
SparseArray<SelectionOverride> selectionOverrides =
|
||||
selectionOverrideBundles == null
|
||||
? new SparseArray<>()
|
||||
@ -1874,32 +1864,40 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
private static final int FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY = FIELD_CUSTOM_ID_BASE;
|
||||
private static final int FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 1;
|
||||
private static final int FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS = FIELD_CUSTOM_ID_BASE + 2;
|
||||
private static final int FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY = FIELD_CUSTOM_ID_BASE + 3;
|
||||
private static final int FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 4;
|
||||
private static final int FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 5;
|
||||
private static final int FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 6;
|
||||
private static final int FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY =
|
||||
FIELD_CUSTOM_ID_BASE + 7;
|
||||
private static final int FIELD_TUNNELING_ENABLED = FIELD_CUSTOM_ID_BASE + 8;
|
||||
private static final int FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS = FIELD_CUSTOM_ID_BASE + 9;
|
||||
private static final int FIELD_SELECTION_OVERRIDES_RENDERER_INDICES = FIELD_CUSTOM_ID_BASE + 10;
|
||||
private static final int FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS =
|
||||
FIELD_CUSTOM_ID_BASE + 11;
|
||||
private static final int FIELD_SELECTION_OVERRIDES = FIELD_CUSTOM_ID_BASE + 12;
|
||||
private static final int FIELD_RENDERER_DISABLED_INDICES = FIELD_CUSTOM_ID_BASE + 13;
|
||||
private static final int FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 14;
|
||||
private static final int FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS =
|
||||
FIELD_CUSTOM_ID_BASE + 15;
|
||||
private static final int FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES =
|
||||
FIELD_CUSTOM_ID_BASE + 16;
|
||||
private static final String FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE);
|
||||
private static final String FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 1);
|
||||
private static final String FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 2);
|
||||
private static final String FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 3);
|
||||
private static final String FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 4);
|
||||
private static final String FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 5);
|
||||
private static final String FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 6);
|
||||
private static final String FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 7);
|
||||
private static final String FIELD_TUNNELING_ENABLED =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 8);
|
||||
private static final String FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 9);
|
||||
private static final String FIELD_SELECTION_OVERRIDES_RENDERER_INDICES =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 10);
|
||||
private static final String FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 11);
|
||||
private static final String FIELD_SELECTION_OVERRIDES =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 12);
|
||||
private static final String FIELD_RENDERER_DISABLED_INDICES =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 13);
|
||||
private static final String FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 14);
|
||||
private static final String FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 15);
|
||||
private static final String FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES =
|
||||
Util.intToStringMaxRadix(FIELD_CUSTOM_ID_BASE + 16);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
@ -1907,49 +1905,40 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
|
||||
// Video
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY),
|
||||
exceedVideoConstraintsIfNecessary);
|
||||
FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY, exceedVideoConstraintsIfNecessary);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS),
|
||||
allowVideoMixedMimeTypeAdaptiveness);
|
||||
FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS, allowVideoMixedMimeTypeAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS),
|
||||
allowVideoNonSeamlessAdaptiveness);
|
||||
FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS, allowVideoNonSeamlessAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS),
|
||||
FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
|
||||
allowVideoMixedDecoderSupportAdaptiveness);
|
||||
// Audio
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY),
|
||||
exceedAudioConstraintsIfNecessary);
|
||||
FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY, exceedAudioConstraintsIfNecessary);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS),
|
||||
allowAudioMixedMimeTypeAdaptiveness);
|
||||
FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS, allowAudioMixedMimeTypeAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS),
|
||||
allowAudioMixedSampleRateAdaptiveness);
|
||||
FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS, allowAudioMixedSampleRateAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS),
|
||||
FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS,
|
||||
allowAudioMixedChannelCountAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS),
|
||||
FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
|
||||
allowAudioMixedDecoderSupportAdaptiveness);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES),
|
||||
FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES,
|
||||
constrainAudioChannelCountToDeviceCapabilities);
|
||||
// General
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY),
|
||||
exceedRendererCapabilitiesIfNecessary);
|
||||
bundle.putBoolean(keyForField(FIELD_TUNNELING_ENABLED), tunnelingEnabled);
|
||||
bundle.putBoolean(
|
||||
keyForField(FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS), allowMultipleAdaptiveSelections);
|
||||
FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY, exceedRendererCapabilitiesIfNecessary);
|
||||
bundle.putBoolean(FIELD_TUNNELING_ENABLED, tunnelingEnabled);
|
||||
bundle.putBoolean(FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS, allowMultipleAdaptiveSelections);
|
||||
|
||||
putSelectionOverridesToBundle(bundle, selectionOverrides);
|
||||
// Only true values are put into rendererDisabledFlags.
|
||||
bundle.putIntArray(
|
||||
keyForField(FIELD_RENDERER_DISABLED_INDICES),
|
||||
getKeysFromSparseBooleanArray(rendererDisabledFlags));
|
||||
FIELD_RENDERER_DISABLED_INDICES, getKeysFromSparseBooleanArray(rendererDisabledFlags));
|
||||
|
||||
return bundle;
|
||||
}
|
||||
@ -1982,12 +1971,12 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
rendererIndices.add(rendererIndex);
|
||||
}
|
||||
bundle.putIntArray(
|
||||
keyForField(FIELD_SELECTION_OVERRIDES_RENDERER_INDICES), Ints.toArray(rendererIndices));
|
||||
FIELD_SELECTION_OVERRIDES_RENDERER_INDICES, Ints.toArray(rendererIndices));
|
||||
bundle.putParcelableArrayList(
|
||||
keyForField(FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS),
|
||||
FIELD_SELECTION_OVERRIDES_TRACK_GROUP_ARRAYS,
|
||||
BundleableUtil.toBundleArrayList(trackGroupArrays));
|
||||
bundle.putSparseParcelableArray(
|
||||
keyForField(FIELD_SELECTION_OVERRIDES), BundleableUtil.toBundleSparseArray(selections));
|
||||
FIELD_SELECTION_OVERRIDES, BundleableUtil.toBundleSparseArray(selections));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2116,27 +2105,17 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_GROUP_INDEX,
|
||||
FIELD_TRACKS,
|
||||
FIELD_TRACK_TYPE,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_GROUP_INDEX = 0;
|
||||
private static final int FIELD_TRACKS = 1;
|
||||
private static final int FIELD_TRACK_TYPE = 2;
|
||||
private static final String FIELD_GROUP_INDEX = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_TRACKS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_TRACK_TYPE = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_GROUP_INDEX), groupIndex);
|
||||
bundle.putIntArray(keyForField(FIELD_TRACKS), tracks);
|
||||
bundle.putInt(keyForField(FIELD_TRACK_TYPE), type);
|
||||
bundle.putInt(FIELD_GROUP_INDEX, groupIndex);
|
||||
bundle.putIntArray(FIELD_TRACKS, tracks);
|
||||
bundle.putInt(FIELD_TRACK_TYPE, type);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -2144,17 +2123,13 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
@UnstableApi
|
||||
public static final Creator<SelectionOverride> CREATOR =
|
||||
bundle -> {
|
||||
int groupIndex = bundle.getInt(keyForField(FIELD_GROUP_INDEX), -1);
|
||||
@Nullable int[] tracks = bundle.getIntArray(keyForField(FIELD_TRACKS));
|
||||
int trackType = bundle.getInt(keyForField(FIELD_TRACK_TYPE), -1);
|
||||
int groupIndex = bundle.getInt(FIELD_GROUP_INDEX, -1);
|
||||
@Nullable int[] tracks = bundle.getIntArray(FIELD_TRACKS);
|
||||
int trackType = bundle.getInt(FIELD_TRACK_TYPE, -1);
|
||||
Assertions.checkArgument(groupIndex >= 0 && trackType >= 0);
|
||||
Assertions.checkNotNull(tracks);
|
||||
return new SelectionOverride(groupIndex, tracks, trackType);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,6 @@ import static androidx.media3.exoplayer.ima.ImaUtil.splitAdGroup;
|
||||
import static androidx.media3.exoplayer.ima.ImaUtil.splitAdPlaybackStateForPeriods;
|
||||
import static androidx.media3.exoplayer.ima.ImaUtil.updateAdDurationInAdGroup;
|
||||
import static androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@ -39,7 +38,6 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Pair;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@ -98,10 +96,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -328,13 +322,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_AD_PLAYBACK_STATES})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_AD_PLAYBACK_STATES = 1;
|
||||
private static final String FIELD_AD_PLAYBACK_STATES = Util.intToStringMaxRadix(1);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
@ -343,7 +331,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||
for (Map.Entry<String, AdPlaybackState> entry : adPlaybackStates.entrySet()) {
|
||||
adPlaybackStatesBundle.putBundle(entry.getKey(), entry.getValue().toBundle());
|
||||
}
|
||||
bundle.putBundle(keyForField(FIELD_AD_PLAYBACK_STATES), adPlaybackStatesBundle);
|
||||
bundle.putBundle(FIELD_AD_PLAYBACK_STATES, adPlaybackStatesBundle);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -354,8 +342,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||
@Nullable
|
||||
ImmutableMap.Builder<String, AdPlaybackState> adPlaybackStateMap =
|
||||
new ImmutableMap.Builder<>();
|
||||
Bundle adPlaybackStateBundle =
|
||||
checkNotNull(bundle.getBundle(keyForField(FIELD_AD_PLAYBACK_STATES)));
|
||||
Bundle adPlaybackStateBundle = checkNotNull(bundle.getBundle(FIELD_AD_PLAYBACK_STATES));
|
||||
for (String key : adPlaybackStateBundle.keySet()) {
|
||||
AdPlaybackState adPlaybackState =
|
||||
AdPlaybackState.CREATOR.fromBundle(
|
||||
@ -365,10 +352,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||
}
|
||||
return new State(adPlaybackStateMap.buildOrThrow());
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
private final ImaUtil.ServerSideAdInsertionConfiguration configuration;
|
||||
|
@ -17,20 +17,15 @@ package androidx.media3.session;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -201,38 +196,25 @@ public final class CommandButton implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_SESSION_COMMAND,
|
||||
FIELD_PLAYER_COMMAND,
|
||||
FIELD_ICON_RES_ID,
|
||||
FIELD_DISPLAY_NAME,
|
||||
FIELD_EXTRAS,
|
||||
FIELD_ENABLED
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_SESSION_COMMAND = 0;
|
||||
private static final int FIELD_PLAYER_COMMAND = 1;
|
||||
private static final int FIELD_ICON_RES_ID = 2;
|
||||
private static final int FIELD_DISPLAY_NAME = 3;
|
||||
private static final int FIELD_EXTRAS = 4;
|
||||
private static final int FIELD_ENABLED = 5;
|
||||
private static final String FIELD_SESSION_COMMAND = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_PLAYER_COMMAND = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_ICON_RES_ID = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_DISPLAY_NAME = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_ENABLED = Util.intToStringMaxRadix(5);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (sessionCommand != null) {
|
||||
bundle.putBundle(keyForField(FIELD_SESSION_COMMAND), sessionCommand.toBundle());
|
||||
bundle.putBundle(FIELD_SESSION_COMMAND, sessionCommand.toBundle());
|
||||
}
|
||||
bundle.putInt(keyForField(FIELD_PLAYER_COMMAND), playerCommand);
|
||||
bundle.putInt(keyForField(FIELD_ICON_RES_ID), iconResId);
|
||||
bundle.putCharSequence(keyForField(FIELD_DISPLAY_NAME), displayName);
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putBoolean(keyForField(FIELD_ENABLED), isEnabled);
|
||||
bundle.putInt(FIELD_PLAYER_COMMAND, playerCommand);
|
||||
bundle.putInt(FIELD_ICON_RES_ID, iconResId);
|
||||
bundle.putCharSequence(FIELD_DISPLAY_NAME, displayName);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
bundle.putBoolean(FIELD_ENABLED, isEnabled);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -240,7 +222,7 @@ public final class CommandButton implements Bundleable {
|
||||
@UnstableApi public static final Creator<CommandButton> CREATOR = CommandButton::fromBundle;
|
||||
|
||||
private static CommandButton fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle sessionCommandBundle = bundle.getBundle(keyForField(FIELD_SESSION_COMMAND));
|
||||
@Nullable Bundle sessionCommandBundle = bundle.getBundle(FIELD_SESSION_COMMAND);
|
||||
@Nullable
|
||||
SessionCommand sessionCommand =
|
||||
sessionCommandBundle == null
|
||||
@ -248,13 +230,11 @@ public final class CommandButton implements Bundleable {
|
||||
: SessionCommand.CREATOR.fromBundle(sessionCommandBundle);
|
||||
@Player.Command
|
||||
int playerCommand =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PLAYER_COMMAND), /* defaultValue= */ Player.COMMAND_INVALID);
|
||||
int iconResId = bundle.getInt(keyForField(FIELD_ICON_RES_ID), /* defaultValue= */ 0);
|
||||
CharSequence displayName =
|
||||
bundle.getCharSequence(keyForField(FIELD_DISPLAY_NAME), /* defaultValue= */ "");
|
||||
@Nullable Bundle extras = bundle.getBundle(keyForField(FIELD_EXTRAS));
|
||||
boolean enabled = bundle.getBoolean(keyForField(FIELD_ENABLED), /* defaultValue= */ false);
|
||||
bundle.getInt(FIELD_PLAYER_COMMAND, /* defaultValue= */ Player.COMMAND_INVALID);
|
||||
int iconResId = bundle.getInt(FIELD_ICON_RES_ID, /* defaultValue= */ 0);
|
||||
CharSequence displayName = bundle.getCharSequence(FIELD_DISPLAY_NAME, /* defaultValue= */ "");
|
||||
@Nullable Bundle extras = bundle.getBundle(FIELD_EXTRAS);
|
||||
boolean enabled = bundle.getBoolean(FIELD_ENABLED, /* defaultValue= */ false);
|
||||
Builder builder = new Builder();
|
||||
if (sessionCommand != null) {
|
||||
builder.setSessionCommand(sessionCommand);
|
||||
@ -269,8 +249,4 @@ public final class CommandButton implements Bundleable {
|
||||
.setEnabled(enabled)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,12 @@ package androidx.media3.session;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.MediaLibraryInfo;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import androidx.media3.common.util.Util;
|
||||
|
||||
/**
|
||||
* Created by {@link MediaController} to send its state to the {@link MediaSession} to request to
|
||||
@ -69,47 +64,34 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_LIBRARY_VERSION,
|
||||
FIELD_PACKAGE_NAME,
|
||||
FIELD_PID,
|
||||
FIELD_CONNECTION_HINTS,
|
||||
FIELD_CONTROLLER_INTERFACE_VERSION
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_LIBRARY_VERSION = 0;
|
||||
private static final int FIELD_PACKAGE_NAME = 1;
|
||||
private static final int FIELD_PID = 2;
|
||||
private static final int FIELD_CONNECTION_HINTS = 3;
|
||||
private static final int FIELD_CONTROLLER_INTERFACE_VERSION = 4;
|
||||
private static final String FIELD_LIBRARY_VERSION = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_PACKAGE_NAME = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_PID = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_CONNECTION_HINTS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_CONTROLLER_INTERFACE_VERSION = Util.intToStringMaxRadix(4);
|
||||
// Next id: 5
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_LIBRARY_VERSION), libraryVersion);
|
||||
bundle.putString(keyForField(FIELD_PACKAGE_NAME), packageName);
|
||||
bundle.putInt(keyForField(FIELD_PID), pid);
|
||||
bundle.putBundle(keyForField(FIELD_CONNECTION_HINTS), connectionHints);
|
||||
bundle.putInt(keyForField(FIELD_CONTROLLER_INTERFACE_VERSION), controllerInterfaceVersion);
|
||||
bundle.putInt(FIELD_LIBRARY_VERSION, libraryVersion);
|
||||
bundle.putString(FIELD_PACKAGE_NAME, packageName);
|
||||
bundle.putInt(FIELD_PID, pid);
|
||||
bundle.putBundle(FIELD_CONNECTION_HINTS, connectionHints);
|
||||
bundle.putInt(FIELD_CONTROLLER_INTERFACE_VERSION, controllerInterfaceVersion);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/** Object that can restore {@link ConnectionRequest} from a {@link Bundle}. */
|
||||
public static final Creator<ConnectionRequest> CREATOR =
|
||||
bundle -> {
|
||||
int libraryVersion =
|
||||
bundle.getInt(keyForField(FIELD_LIBRARY_VERSION), /* defaultValue= */ 0);
|
||||
int libraryVersion = bundle.getInt(FIELD_LIBRARY_VERSION, /* defaultValue= */ 0);
|
||||
int controllerInterfaceVersion =
|
||||
bundle.getInt(keyForField(FIELD_CONTROLLER_INTERFACE_VERSION), /* defaultValue= */ 0);
|
||||
String packageName = checkNotNull(bundle.getString(keyForField(FIELD_PACKAGE_NAME)));
|
||||
int pid = bundle.getInt(keyForField(FIELD_PID), /* defaultValue= */ 0);
|
||||
bundle.getInt(FIELD_CONTROLLER_INTERFACE_VERSION, /* defaultValue= */ 0);
|
||||
String packageName = checkNotNull(bundle.getString(FIELD_PACKAGE_NAME));
|
||||
int pid = bundle.getInt(FIELD_PID, /* defaultValue= */ 0);
|
||||
checkArgument(pid != 0);
|
||||
@Nullable Bundle connectionHints = bundle.getBundle(keyForField(FIELD_CONNECTION_HINTS));
|
||||
@Nullable Bundle connectionHints = bundle.getBundle(FIELD_CONNECTION_HINTS);
|
||||
return new ConnectionRequest(
|
||||
libraryVersion,
|
||||
controllerInterfaceVersion,
|
||||
@ -117,8 +99,4 @@ import java.lang.annotation.Target;
|
||||
pid,
|
||||
connectionHints == null ? Bundle.EMPTY : connectionHints);
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,15 @@
|
||||
package androidx.media3.session;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.BundleCompat;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.Player;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import androidx.media3.common.util.Util;
|
||||
|
||||
/**
|
||||
* Created by {@link MediaSession} to send its state to the {@link MediaController} when the
|
||||
@ -78,47 +73,29 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_LIBRARY_VERSION,
|
||||
FIELD_SESSION_BINDER,
|
||||
FIELD_SESSION_ACTIVITY,
|
||||
FIELD_SESSION_COMMANDS,
|
||||
FIELD_PLAYER_COMMANDS_FROM_SESSION,
|
||||
FIELD_PLAYER_COMMANDS_FROM_PLAYER,
|
||||
FIELD_TOKEN_EXTRAS,
|
||||
FIELD_PLAYER_INFO,
|
||||
FIELD_SESSION_INTERFACE_VERSION,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_LIBRARY_VERSION = 0;
|
||||
private static final int FIELD_SESSION_BINDER = 1;
|
||||
private static final int FIELD_SESSION_ACTIVITY = 2;
|
||||
private static final int FIELD_SESSION_COMMANDS = 3;
|
||||
private static final int FIELD_PLAYER_COMMANDS_FROM_SESSION = 4;
|
||||
private static final int FIELD_PLAYER_COMMANDS_FROM_PLAYER = 5;
|
||||
private static final int FIELD_TOKEN_EXTRAS = 6;
|
||||
private static final int FIELD_PLAYER_INFO = 7;
|
||||
private static final int FIELD_SESSION_INTERFACE_VERSION = 8;
|
||||
private static final String FIELD_LIBRARY_VERSION = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_SESSION_BINDER = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_SESSION_ACTIVITY = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_SESSION_COMMANDS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_PLAYER_COMMANDS_FROM_SESSION = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_PLAYER_COMMANDS_FROM_PLAYER = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_TOKEN_EXTRAS = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_PLAYER_INFO = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_SESSION_INTERFACE_VERSION = Util.intToStringMaxRadix(8);
|
||||
// Next field key = 9
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_LIBRARY_VERSION), libraryVersion);
|
||||
BundleCompat.putBinder(bundle, keyForField(FIELD_SESSION_BINDER), sessionBinder.asBinder());
|
||||
bundle.putParcelable(keyForField(FIELD_SESSION_ACTIVITY), sessionActivity);
|
||||
bundle.putBundle(keyForField(FIELD_SESSION_COMMANDS), sessionCommands.toBundle());
|
||||
bundle.putInt(FIELD_LIBRARY_VERSION, libraryVersion);
|
||||
BundleCompat.putBinder(bundle, FIELD_SESSION_BINDER, sessionBinder.asBinder());
|
||||
bundle.putParcelable(FIELD_SESSION_ACTIVITY, sessionActivity);
|
||||
bundle.putBundle(FIELD_SESSION_COMMANDS, sessionCommands.toBundle());
|
||||
bundle.putBundle(FIELD_PLAYER_COMMANDS_FROM_SESSION, playerCommandsFromSession.toBundle());
|
||||
bundle.putBundle(FIELD_PLAYER_COMMANDS_FROM_PLAYER, playerCommandsFromPlayer.toBundle());
|
||||
bundle.putBundle(FIELD_TOKEN_EXTRAS, tokenExtras);
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_PLAYER_COMMANDS_FROM_SESSION), playerCommandsFromSession.toBundle());
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_PLAYER_COMMANDS_FROM_PLAYER), playerCommandsFromPlayer.toBundle());
|
||||
bundle.putBundle(keyForField(FIELD_TOKEN_EXTRAS), tokenExtras);
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_PLAYER_INFO),
|
||||
FIELD_PLAYER_INFO,
|
||||
playerInfo.toBundle(
|
||||
/* excludeMediaItems= */ !playerCommandsFromPlayer.contains(Player.COMMAND_GET_TIMELINE)
|
||||
|| !playerCommandsFromSession.contains(Player.COMMAND_GET_TIMELINE),
|
||||
@ -130,7 +107,7 @@ import java.lang.annotation.Target;
|
||||
/* excludeTimeline= */ false,
|
||||
/* excludeTracks= */ !playerCommandsFromPlayer.contains(Player.COMMAND_GET_TRACKS)
|
||||
|| !playerCommandsFromSession.contains(Player.COMMAND_GET_TRACKS)));
|
||||
bundle.putInt(keyForField(FIELD_SESSION_INTERFACE_VERSION), sessionInterfaceVersion);
|
||||
bundle.putInt(FIELD_SESSION_INTERFACE_VERSION, sessionInterfaceVersion);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -138,34 +115,30 @@ import java.lang.annotation.Target;
|
||||
public static final Creator<ConnectionState> CREATOR = ConnectionState::fromBundle;
|
||||
|
||||
private static ConnectionState fromBundle(Bundle bundle) {
|
||||
int libraryVersion = bundle.getInt(keyForField(FIELD_LIBRARY_VERSION), /* defaultValue= */ 0);
|
||||
int libraryVersion = bundle.getInt(FIELD_LIBRARY_VERSION, /* defaultValue= */ 0);
|
||||
int sessionInterfaceVersion =
|
||||
bundle.getInt(keyForField(FIELD_SESSION_INTERFACE_VERSION), /* defaultValue= */ 0);
|
||||
IBinder sessionBinder =
|
||||
checkNotNull(BundleCompat.getBinder(bundle, keyForField(FIELD_SESSION_BINDER)));
|
||||
@Nullable
|
||||
PendingIntent sessionActivity = bundle.getParcelable(keyForField(FIELD_SESSION_ACTIVITY));
|
||||
@Nullable Bundle sessionCommandsBundle = bundle.getBundle(keyForField(FIELD_SESSION_COMMANDS));
|
||||
bundle.getInt(FIELD_SESSION_INTERFACE_VERSION, /* defaultValue= */ 0);
|
||||
IBinder sessionBinder = checkNotNull(BundleCompat.getBinder(bundle, FIELD_SESSION_BINDER));
|
||||
@Nullable PendingIntent sessionActivity = bundle.getParcelable(FIELD_SESSION_ACTIVITY);
|
||||
@Nullable Bundle sessionCommandsBundle = bundle.getBundle(FIELD_SESSION_COMMANDS);
|
||||
SessionCommands sessionCommands =
|
||||
sessionCommandsBundle == null
|
||||
? SessionCommands.EMPTY
|
||||
: SessionCommands.CREATOR.fromBundle(sessionCommandsBundle);
|
||||
@Nullable
|
||||
Bundle playerCommandsFromPlayerBundle =
|
||||
bundle.getBundle(keyForField(FIELD_PLAYER_COMMANDS_FROM_PLAYER));
|
||||
Bundle playerCommandsFromPlayerBundle = bundle.getBundle(FIELD_PLAYER_COMMANDS_FROM_PLAYER);
|
||||
Player.Commands playerCommandsFromPlayer =
|
||||
playerCommandsFromPlayerBundle == null
|
||||
? Player.Commands.EMPTY
|
||||
: Player.Commands.CREATOR.fromBundle(playerCommandsFromPlayerBundle);
|
||||
@Nullable
|
||||
Bundle playerCommandsFromSessionBundle =
|
||||
bundle.getBundle(keyForField(FIELD_PLAYER_COMMANDS_FROM_SESSION));
|
||||
Bundle playerCommandsFromSessionBundle = bundle.getBundle(FIELD_PLAYER_COMMANDS_FROM_SESSION);
|
||||
Player.Commands playerCommandsFromSession =
|
||||
playerCommandsFromSessionBundle == null
|
||||
? Player.Commands.EMPTY
|
||||
: Player.Commands.CREATOR.fromBundle(playerCommandsFromSessionBundle);
|
||||
@Nullable Bundle tokenExtras = bundle.getBundle(keyForField(FIELD_TOKEN_EXTRAS));
|
||||
@Nullable Bundle playerInfoBundle = bundle.getBundle(keyForField(FIELD_PLAYER_INFO));
|
||||
@Nullable Bundle tokenExtras = bundle.getBundle(FIELD_TOKEN_EXTRAS);
|
||||
@Nullable Bundle playerInfoBundle = bundle.getBundle(FIELD_PLAYER_INFO);
|
||||
PlayerInfo playerInfo =
|
||||
playerInfoBundle == null
|
||||
? PlayerInfo.DEFAULT
|
||||
@ -181,8 +154,4 @@ import java.lang.annotation.Target;
|
||||
tokenExtras == null ? Bundle.EMPTY : tokenExtras,
|
||||
playerInfo);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.MediaMetadata;
|
||||
import androidx.media3.common.util.BundleableUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.session.MediaLibraryService.LibraryParams;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
@ -262,23 +263,11 @@ public final class LibraryResult<V> implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_RESULT_CODE,
|
||||
FIELD_COMPLETION_TIME_MS,
|
||||
FIELD_PARAMS,
|
||||
FIELD_VALUE,
|
||||
FIELD_VALUE_TYPE
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_RESULT_CODE = 0;
|
||||
private static final int FIELD_COMPLETION_TIME_MS = 1;
|
||||
private static final int FIELD_PARAMS = 2;
|
||||
private static final int FIELD_VALUE = 3;
|
||||
private static final int FIELD_VALUE_TYPE = 4;
|
||||
private static final String FIELD_RESULT_CODE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_COMPLETION_TIME_MS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_PARAMS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_VALUE = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_VALUE_TYPE = Util.intToStringMaxRadix(4);
|
||||
|
||||
// Casting V to ImmutableList<MediaItem> is safe if valueType == VALUE_TYPE_ITEM_LIST.
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -286,24 +275,24 @@ public final class LibraryResult<V> implements Bundleable {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RESULT_CODE), resultCode);
|
||||
bundle.putLong(keyForField(FIELD_COMPLETION_TIME_MS), completionTimeMs);
|
||||
bundle.putInt(FIELD_RESULT_CODE, resultCode);
|
||||
bundle.putLong(FIELD_COMPLETION_TIME_MS, completionTimeMs);
|
||||
if (params != null) {
|
||||
bundle.putBundle(keyForField(FIELD_PARAMS), params.toBundle());
|
||||
bundle.putBundle(FIELD_PARAMS, params.toBundle());
|
||||
}
|
||||
bundle.putInt(keyForField(FIELD_VALUE_TYPE), valueType);
|
||||
bundle.putInt(FIELD_VALUE_TYPE, valueType);
|
||||
|
||||
if (value == null) {
|
||||
return bundle;
|
||||
}
|
||||
switch (valueType) {
|
||||
case VALUE_TYPE_ITEM:
|
||||
bundle.putBundle(keyForField(FIELD_VALUE), ((MediaItem) value).toBundle());
|
||||
bundle.putBundle(FIELD_VALUE, ((MediaItem) value).toBundle());
|
||||
break;
|
||||
case VALUE_TYPE_ITEM_LIST:
|
||||
BundleCompat.putBinder(
|
||||
bundle,
|
||||
keyForField(FIELD_VALUE),
|
||||
FIELD_VALUE,
|
||||
new BundleListRetriever(BundleableUtil.toBundleList((ImmutableList<MediaItem>) value)));
|
||||
break;
|
||||
case VALUE_TYPE_VOID:
|
||||
@ -367,27 +356,24 @@ public final class LibraryResult<V> implements Bundleable {
|
||||
*/
|
||||
private static LibraryResult<?> fromBundle(
|
||||
Bundle bundle, @Nullable @ValueType Integer expectedType) {
|
||||
int resultCode =
|
||||
bundle.getInt(keyForField(FIELD_RESULT_CODE), /* defaultValue= */ RESULT_SUCCESS);
|
||||
int resultCode = bundle.getInt(FIELD_RESULT_CODE, /* defaultValue= */ RESULT_SUCCESS);
|
||||
long completionTimeMs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_COMPLETION_TIME_MS),
|
||||
/* defaultValue= */ SystemClock.elapsedRealtime());
|
||||
@Nullable Bundle paramsBundle = bundle.getBundle(keyForField(FIELD_PARAMS));
|
||||
bundle.getLong(FIELD_COMPLETION_TIME_MS, /* defaultValue= */ SystemClock.elapsedRealtime());
|
||||
@Nullable Bundle paramsBundle = bundle.getBundle(FIELD_PARAMS);
|
||||
@Nullable
|
||||
MediaLibraryService.LibraryParams params =
|
||||
paramsBundle == null ? null : LibraryParams.CREATOR.fromBundle(paramsBundle);
|
||||
@ValueType int valueType = bundle.getInt(keyForField(FIELD_VALUE_TYPE));
|
||||
@ValueType int valueType = bundle.getInt(FIELD_VALUE_TYPE);
|
||||
@Nullable Object value;
|
||||
switch (valueType) {
|
||||
case VALUE_TYPE_ITEM:
|
||||
checkState(expectedType == null || expectedType == VALUE_TYPE_ITEM);
|
||||
@Nullable Bundle valueBundle = bundle.getBundle(keyForField(FIELD_VALUE));
|
||||
@Nullable Bundle valueBundle = bundle.getBundle(FIELD_VALUE);
|
||||
value = valueBundle == null ? null : MediaItem.CREATOR.fromBundle(valueBundle);
|
||||
break;
|
||||
case VALUE_TYPE_ITEM_LIST:
|
||||
checkState(expectedType == null || expectedType == VALUE_TYPE_ITEM_LIST);
|
||||
@Nullable IBinder valueRetriever = BundleCompat.getBinder(bundle, keyForField(FIELD_VALUE));
|
||||
@Nullable IBinder valueRetriever = BundleCompat.getBinder(bundle, FIELD_VALUE);
|
||||
value =
|
||||
valueRetriever == null
|
||||
? null
|
||||
@ -405,10 +391,6 @@ public final class LibraryResult<V> implements Bundleable {
|
||||
return new LibraryResult<>(resultCode, completionTimeMs, params, value, VALUE_TYPE_ITEM_LIST);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
|
@ -19,7 +19,6 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotEmpty;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.session.LibraryResult.RESULT_ERROR_NOT_SUPPORTED;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
@ -27,7 +26,6 @@ import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media.MediaSessionManager.RemoteUserInfo;
|
||||
@ -36,15 +34,12 @@ import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.MediaMetadata;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.session.MediaSession.ControllerInfo;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Superclass to be extended by services hosting {@link MediaLibrarySession media library sessions}.
|
||||
@ -666,30 +661,19 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_EXTRAS,
|
||||
FIELD_RECENT,
|
||||
FIELD_OFFLINE,
|
||||
FIELD_SUGGESTED,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_EXTRAS = 0;
|
||||
private static final int FIELD_RECENT = 1;
|
||||
private static final int FIELD_OFFLINE = 2;
|
||||
private static final int FIELD_SUGGESTED = 3;
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_RECENT = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_OFFLINE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_SUGGESTED = Util.intToStringMaxRadix(3);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putBoolean(keyForField(FIELD_RECENT), isRecent);
|
||||
bundle.putBoolean(keyForField(FIELD_OFFLINE), isOffline);
|
||||
bundle.putBoolean(keyForField(FIELD_SUGGESTED), isSuggested);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
bundle.putBoolean(FIELD_RECENT, isRecent);
|
||||
bundle.putBoolean(FIELD_OFFLINE, isOffline);
|
||||
bundle.putBoolean(FIELD_SUGGESTED, isSuggested);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -697,17 +681,12 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
||||
@UnstableApi public static final Creator<LibraryParams> CREATOR = LibraryParams::fromBundle;
|
||||
|
||||
private static LibraryParams fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle extras = bundle.getBundle(keyForField(FIELD_EXTRAS));
|
||||
boolean recent = bundle.getBoolean(keyForField(FIELD_RECENT), /* defaultValue= */ false);
|
||||
boolean offline = bundle.getBoolean(keyForField(FIELD_OFFLINE), /* defaultValue= */ false);
|
||||
boolean suggested =
|
||||
bundle.getBoolean(keyForField(FIELD_SUGGESTED), /* defaultValue= */ false);
|
||||
@Nullable Bundle extras = bundle.getBundle(FIELD_EXTRAS);
|
||||
boolean recent = bundle.getBoolean(FIELD_RECENT, /* defaultValue= */ false);
|
||||
boolean offline = bundle.getBoolean(FIELD_OFFLINE, /* defaultValue= */ false);
|
||||
boolean suggested = bundle.getBoolean(FIELD_SUGGESTED, /* defaultValue= */ false);
|
||||
return new LibraryParams(extras == null ? Bundle.EMPTY : extras, recent, offline, suggested);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,13 +20,11 @@ import static androidx.media3.common.Player.MEDIA_ITEM_TRANSITION_REASON_REPEAT;
|
||||
import static androidx.media3.common.Player.PLAYBACK_SUPPRESSION_REASON_NONE;
|
||||
import static androidx.media3.common.Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST;
|
||||
import static androidx.media3.common.Player.STATE_IDLE;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.AudioAttributes;
|
||||
import androidx.media3.common.Bundleable;
|
||||
@ -47,12 +45,9 @@ import androidx.media3.common.VideoSize;
|
||||
import androidx.media3.common.text.CueGroup;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Information about the player that {@link MediaSession} uses to send its state to {@link
|
||||
@ -83,36 +78,24 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_IS_TIMELINE_EXCLUDED, FIELD_ARE_CURRENT_TRACKS_EXCLUDED})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_IS_TIMELINE_EXCLUDED = 0;
|
||||
private static final int FIELD_ARE_CURRENT_TRACKS_EXCLUDED = 1;
|
||||
private static final String FIELD_IS_TIMELINE_EXCLUDED = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_ARE_CURRENT_TRACKS_EXCLUDED = Util.intToStringMaxRadix(1);
|
||||
// Next field key = 2
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(keyForField(FIELD_IS_TIMELINE_EXCLUDED), isTimelineExcluded);
|
||||
bundle.putBoolean(keyForField(FIELD_ARE_CURRENT_TRACKS_EXCLUDED), areCurrentTracksExcluded);
|
||||
bundle.putBoolean(FIELD_IS_TIMELINE_EXCLUDED, isTimelineExcluded);
|
||||
bundle.putBoolean(FIELD_ARE_CURRENT_TRACKS_EXCLUDED, areCurrentTracksExcluded);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public static final Creator<BundlingExclusions> CREATOR =
|
||||
bundle ->
|
||||
new BundlingExclusions(
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_IS_TIMELINE_EXCLUDED), /* defaultValue= */ false),
|
||||
bundle.getBoolean(
|
||||
keyForField(FIELD_ARE_CURRENT_TRACKS_EXCLUDED), /* defaultValue= */ false));
|
||||
|
||||
private static String keyForField(@BundlingExclusions.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
bundle.getBoolean(FIELD_IS_TIMELINE_EXCLUDED, /* defaultValue= */ false),
|
||||
bundle.getBoolean(FIELD_ARE_CURRENT_TRACKS_EXCLUDED, /* defaultValue= */ false));
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
@ -783,73 +766,36 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_PLAYBACK_PARAMETERS,
|
||||
FIELD_REPEAT_MODE,
|
||||
FIELD_SHUFFLE_MODE_ENABLED,
|
||||
FIELD_TIMELINE,
|
||||
FIELD_VIDEO_SIZE,
|
||||
FIELD_PLAYLIST_METADATA,
|
||||
FIELD_VOLUME,
|
||||
FIELD_AUDIO_ATTRIBUTES,
|
||||
FIELD_DEVICE_INFO,
|
||||
FIELD_DEVICE_VOLUME,
|
||||
FIELD_DEVICE_MUTED,
|
||||
FIELD_PLAY_WHEN_READY,
|
||||
FIELD_PLAY_WHEN_READY_CHANGED_REASON,
|
||||
FIELD_PLAYBACK_SUPPRESSION_REASON,
|
||||
FIELD_PLAYBACK_STATE,
|
||||
FIELD_IS_PLAYING,
|
||||
FIELD_IS_LOADING,
|
||||
FIELD_PLAYBACK_ERROR,
|
||||
FIELD_SESSION_POSITION_INFO,
|
||||
FIELD_MEDIA_ITEM_TRANSITION_REASON,
|
||||
FIELD_OLD_POSITION_INFO,
|
||||
FIELD_NEW_POSITION_INFO,
|
||||
FIELD_DISCONTINUITY_REASON,
|
||||
FIELD_CUE_GROUP,
|
||||
FIELD_MEDIA_METADATA,
|
||||
FIELD_SEEK_BACK_INCREMENT_MS,
|
||||
FIELD_SEEK_FORWARD_INCREMENT_MS,
|
||||
FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS,
|
||||
FIELD_TRACK_SELECTION_PARAMETERS,
|
||||
FIELD_CURRENT_TRACKS,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_PLAYBACK_PARAMETERS = 1;
|
||||
private static final int FIELD_REPEAT_MODE = 2;
|
||||
private static final int FIELD_SHUFFLE_MODE_ENABLED = 3;
|
||||
private static final int FIELD_TIMELINE = 4;
|
||||
private static final int FIELD_VIDEO_SIZE = 5;
|
||||
private static final int FIELD_PLAYLIST_METADATA = 6;
|
||||
private static final int FIELD_VOLUME = 7;
|
||||
private static final int FIELD_AUDIO_ATTRIBUTES = 8;
|
||||
private static final int FIELD_DEVICE_INFO = 9;
|
||||
private static final int FIELD_DEVICE_VOLUME = 10;
|
||||
private static final int FIELD_DEVICE_MUTED = 11;
|
||||
private static final int FIELD_PLAY_WHEN_READY = 12;
|
||||
private static final int FIELD_PLAY_WHEN_READY_CHANGED_REASON = 13;
|
||||
private static final int FIELD_PLAYBACK_SUPPRESSION_REASON = 14;
|
||||
private static final int FIELD_PLAYBACK_STATE = 15;
|
||||
private static final int FIELD_IS_PLAYING = 16;
|
||||
private static final int FIELD_IS_LOADING = 17;
|
||||
private static final int FIELD_PLAYBACK_ERROR = 18;
|
||||
private static final int FIELD_SESSION_POSITION_INFO = 19;
|
||||
private static final int FIELD_MEDIA_ITEM_TRANSITION_REASON = 20;
|
||||
private static final int FIELD_OLD_POSITION_INFO = 21;
|
||||
private static final int FIELD_NEW_POSITION_INFO = 22;
|
||||
private static final int FIELD_DISCONTINUITY_REASON = 23;
|
||||
private static final int FIELD_CUE_GROUP = 24;
|
||||
private static final int FIELD_MEDIA_METADATA = 25;
|
||||
private static final int FIELD_SEEK_BACK_INCREMENT_MS = 26;
|
||||
private static final int FIELD_SEEK_FORWARD_INCREMENT_MS = 27;
|
||||
private static final int FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS = 28;
|
||||
private static final int FIELD_TRACK_SELECTION_PARAMETERS = 29;
|
||||
private static final int FIELD_CURRENT_TRACKS = 30;
|
||||
private static final String FIELD_PLAYBACK_PARAMETERS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_REPEAT_MODE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_SHUFFLE_MODE_ENABLED = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_TIMELINE = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_VIDEO_SIZE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_PLAYLIST_METADATA = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_VOLUME = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_AUDIO_ATTRIBUTES = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_DEVICE_INFO = Util.intToStringMaxRadix(9);
|
||||
private static final String FIELD_DEVICE_VOLUME = Util.intToStringMaxRadix(10);
|
||||
private static final String FIELD_DEVICE_MUTED = Util.intToStringMaxRadix(11);
|
||||
private static final String FIELD_PLAY_WHEN_READY = Util.intToStringMaxRadix(12);
|
||||
private static final String FIELD_PLAY_WHEN_READY_CHANGED_REASON = Util.intToStringMaxRadix(13);
|
||||
private static final String FIELD_PLAYBACK_SUPPRESSION_REASON = Util.intToStringMaxRadix(14);
|
||||
private static final String FIELD_PLAYBACK_STATE = Util.intToStringMaxRadix(15);
|
||||
private static final String FIELD_IS_PLAYING = Util.intToStringMaxRadix(16);
|
||||
private static final String FIELD_IS_LOADING = Util.intToStringMaxRadix(17);
|
||||
private static final String FIELD_PLAYBACK_ERROR = Util.intToStringMaxRadix(18);
|
||||
private static final String FIELD_SESSION_POSITION_INFO = Util.intToStringMaxRadix(19);
|
||||
private static final String FIELD_MEDIA_ITEM_TRANSITION_REASON = Util.intToStringMaxRadix(20);
|
||||
private static final String FIELD_OLD_POSITION_INFO = Util.intToStringMaxRadix(21);
|
||||
private static final String FIELD_NEW_POSITION_INFO = Util.intToStringMaxRadix(22);
|
||||
private static final String FIELD_DISCONTINUITY_REASON = Util.intToStringMaxRadix(23);
|
||||
private static final String FIELD_CUE_GROUP = Util.intToStringMaxRadix(24);
|
||||
private static final String FIELD_MEDIA_METADATA = Util.intToStringMaxRadix(25);
|
||||
private static final String FIELD_SEEK_BACK_INCREMENT_MS = Util.intToStringMaxRadix(26);
|
||||
private static final String FIELD_SEEK_FORWARD_INCREMENT_MS = Util.intToStringMaxRadix(27);
|
||||
private static final String FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS = Util.intToStringMaxRadix(28);
|
||||
private static final String FIELD_TRACK_SELECTION_PARAMETERS = Util.intToStringMaxRadix(29);
|
||||
private static final String FIELD_CURRENT_TRACKS = Util.intToStringMaxRadix(30);
|
||||
// Next field key = 31
|
||||
|
||||
public Bundle toBundle(
|
||||
@ -860,48 +806,46 @@ import java.lang.annotation.Target;
|
||||
boolean excludeTracks) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (playerError != null) {
|
||||
bundle.putBundle(keyForField(FIELD_PLAYBACK_ERROR), playerError.toBundle());
|
||||
bundle.putBundle(FIELD_PLAYBACK_ERROR, playerError.toBundle());
|
||||
}
|
||||
bundle.putInt(keyForField(FIELD_MEDIA_ITEM_TRANSITION_REASON), mediaItemTransitionReason);
|
||||
bundle.putBundle(keyForField(FIELD_SESSION_POSITION_INFO), sessionPositionInfo.toBundle());
|
||||
bundle.putBundle(keyForField(FIELD_OLD_POSITION_INFO), oldPositionInfo.toBundle());
|
||||
bundle.putBundle(keyForField(FIELD_NEW_POSITION_INFO), newPositionInfo.toBundle());
|
||||
bundle.putInt(keyForField(FIELD_DISCONTINUITY_REASON), discontinuityReason);
|
||||
bundle.putBundle(keyForField(FIELD_PLAYBACK_PARAMETERS), playbackParameters.toBundle());
|
||||
bundle.putInt(keyForField(FIELD_REPEAT_MODE), repeatMode);
|
||||
bundle.putBoolean(keyForField(FIELD_SHUFFLE_MODE_ENABLED), shuffleModeEnabled);
|
||||
bundle.putInt(FIELD_MEDIA_ITEM_TRANSITION_REASON, mediaItemTransitionReason);
|
||||
bundle.putBundle(FIELD_SESSION_POSITION_INFO, sessionPositionInfo.toBundle());
|
||||
bundle.putBundle(FIELD_OLD_POSITION_INFO, oldPositionInfo.toBundle());
|
||||
bundle.putBundle(FIELD_NEW_POSITION_INFO, newPositionInfo.toBundle());
|
||||
bundle.putInt(FIELD_DISCONTINUITY_REASON, discontinuityReason);
|
||||
bundle.putBundle(FIELD_PLAYBACK_PARAMETERS, playbackParameters.toBundle());
|
||||
bundle.putInt(FIELD_REPEAT_MODE, repeatMode);
|
||||
bundle.putBoolean(FIELD_SHUFFLE_MODE_ENABLED, shuffleModeEnabled);
|
||||
if (!excludeTimeline) {
|
||||
bundle.putBundle(keyForField(FIELD_TIMELINE), timeline.toBundle(excludeMediaItems));
|
||||
bundle.putBundle(FIELD_TIMELINE, timeline.toBundle(excludeMediaItems));
|
||||
}
|
||||
bundle.putBundle(keyForField(FIELD_VIDEO_SIZE), videoSize.toBundle());
|
||||
bundle.putBundle(FIELD_VIDEO_SIZE, videoSize.toBundle());
|
||||
if (!excludeMediaItemsMetadata) {
|
||||
bundle.putBundle(keyForField(FIELD_PLAYLIST_METADATA), playlistMetadata.toBundle());
|
||||
bundle.putBundle(FIELD_PLAYLIST_METADATA, playlistMetadata.toBundle());
|
||||
}
|
||||
bundle.putFloat(keyForField(FIELD_VOLUME), volume);
|
||||
bundle.putBundle(keyForField(FIELD_AUDIO_ATTRIBUTES), audioAttributes.toBundle());
|
||||
bundle.putFloat(FIELD_VOLUME, volume);
|
||||
bundle.putBundle(FIELD_AUDIO_ATTRIBUTES, audioAttributes.toBundle());
|
||||
if (!excludeCues) {
|
||||
bundle.putBundle(keyForField(FIELD_CUE_GROUP), cueGroup.toBundle());
|
||||
bundle.putBundle(FIELD_CUE_GROUP, cueGroup.toBundle());
|
||||
}
|
||||
bundle.putBundle(keyForField(FIELD_DEVICE_INFO), deviceInfo.toBundle());
|
||||
bundle.putInt(keyForField(FIELD_DEVICE_VOLUME), deviceVolume);
|
||||
bundle.putBoolean(keyForField(FIELD_DEVICE_MUTED), deviceMuted);
|
||||
bundle.putBoolean(keyForField(FIELD_PLAY_WHEN_READY), playWhenReady);
|
||||
bundle.putInt(keyForField(FIELD_PLAYBACK_SUPPRESSION_REASON), playbackSuppressionReason);
|
||||
bundle.putInt(keyForField(FIELD_PLAYBACK_STATE), playbackState);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLAYING), isPlaying);
|
||||
bundle.putBoolean(keyForField(FIELD_IS_LOADING), isLoading);
|
||||
bundle.putBundle(FIELD_DEVICE_INFO, deviceInfo.toBundle());
|
||||
bundle.putInt(FIELD_DEVICE_VOLUME, deviceVolume);
|
||||
bundle.putBoolean(FIELD_DEVICE_MUTED, deviceMuted);
|
||||
bundle.putBoolean(FIELD_PLAY_WHEN_READY, playWhenReady);
|
||||
bundle.putInt(FIELD_PLAYBACK_SUPPRESSION_REASON, playbackSuppressionReason);
|
||||
bundle.putInt(FIELD_PLAYBACK_STATE, playbackState);
|
||||
bundle.putBoolean(FIELD_IS_PLAYING, isPlaying);
|
||||
bundle.putBoolean(FIELD_IS_LOADING, isLoading);
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_MEDIA_METADATA),
|
||||
FIELD_MEDIA_METADATA,
|
||||
excludeMediaItems ? MediaMetadata.EMPTY.toBundle() : mediaMetadata.toBundle());
|
||||
bundle.putLong(keyForField(FIELD_SEEK_BACK_INCREMENT_MS), seekBackIncrementMs);
|
||||
bundle.putLong(keyForField(FIELD_SEEK_FORWARD_INCREMENT_MS), seekForwardIncrementMs);
|
||||
bundle.putLong(
|
||||
keyForField(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS), maxSeekToPreviousPositionMs);
|
||||
bundle.putLong(FIELD_SEEK_BACK_INCREMENT_MS, seekBackIncrementMs);
|
||||
bundle.putLong(FIELD_SEEK_FORWARD_INCREMENT_MS, seekForwardIncrementMs);
|
||||
bundle.putLong(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS, maxSeekToPreviousPositionMs);
|
||||
if (!excludeTracks) {
|
||||
bundle.putBundle(keyForField(FIELD_CURRENT_TRACKS), currentTracks.toBundle());
|
||||
bundle.putBundle(FIELD_CURRENT_TRACKS, currentTracks.toBundle());
|
||||
}
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_TRACK_SELECTION_PARAMETERS), trackSelectionParameters.toBundle());
|
||||
bundle.putBundle(FIELD_TRACK_SELECTION_PARAMETERS, trackSelectionParameters.toBundle());
|
||||
|
||||
return bundle;
|
||||
}
|
||||
@ -920,107 +864,96 @@ import java.lang.annotation.Target;
|
||||
public static final Creator<PlayerInfo> CREATOR = PlayerInfo::fromBundle;
|
||||
|
||||
private static PlayerInfo fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle playerErrorBundle = bundle.getBundle(keyForField(FIELD_PLAYBACK_ERROR));
|
||||
@Nullable Bundle playerErrorBundle = bundle.getBundle(FIELD_PLAYBACK_ERROR);
|
||||
@Nullable
|
||||
PlaybackException playerError =
|
||||
playerErrorBundle == null ? null : PlaybackException.CREATOR.fromBundle(playerErrorBundle);
|
||||
int mediaItemTransitionReason =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_MEDIA_ITEM_TRANSITION_REASON), MEDIA_ITEM_TRANSITION_REASON_REPEAT);
|
||||
@Nullable
|
||||
Bundle sessionPositionInfoBundle = bundle.getBundle(keyForField(FIELD_SESSION_POSITION_INFO));
|
||||
bundle.getInt(FIELD_MEDIA_ITEM_TRANSITION_REASON, MEDIA_ITEM_TRANSITION_REASON_REPEAT);
|
||||
@Nullable Bundle sessionPositionInfoBundle = bundle.getBundle(FIELD_SESSION_POSITION_INFO);
|
||||
SessionPositionInfo sessionPositionInfo =
|
||||
sessionPositionInfoBundle == null
|
||||
? SessionPositionInfo.DEFAULT
|
||||
: SessionPositionInfo.CREATOR.fromBundle(sessionPositionInfoBundle);
|
||||
@Nullable Bundle oldPositionInfoBundle = bundle.getBundle(keyForField(FIELD_OLD_POSITION_INFO));
|
||||
@Nullable Bundle oldPositionInfoBundle = bundle.getBundle(FIELD_OLD_POSITION_INFO);
|
||||
PositionInfo oldPositionInfo =
|
||||
oldPositionInfoBundle == null
|
||||
? SessionPositionInfo.DEFAULT_POSITION_INFO
|
||||
: PositionInfo.CREATOR.fromBundle(oldPositionInfoBundle);
|
||||
@Nullable Bundle newPositionInfoBundle = bundle.getBundle(keyForField(FIELD_NEW_POSITION_INFO));
|
||||
@Nullable Bundle newPositionInfoBundle = bundle.getBundle(FIELD_NEW_POSITION_INFO);
|
||||
PositionInfo newPositionInfo =
|
||||
newPositionInfoBundle == null
|
||||
? SessionPositionInfo.DEFAULT_POSITION_INFO
|
||||
: PositionInfo.CREATOR.fromBundle(newPositionInfoBundle);
|
||||
int discontinuityReason =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_DISCONTINUITY_REASON), DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||
@Nullable
|
||||
Bundle playbackParametersBundle = bundle.getBundle(keyForField(FIELD_PLAYBACK_PARAMETERS));
|
||||
bundle.getInt(FIELD_DISCONTINUITY_REASON, DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||
@Nullable Bundle playbackParametersBundle = bundle.getBundle(FIELD_PLAYBACK_PARAMETERS);
|
||||
PlaybackParameters playbackParameters =
|
||||
playbackParametersBundle == null
|
||||
? PlaybackParameters.DEFAULT
|
||||
: PlaybackParameters.CREATOR.fromBundle(playbackParametersBundle);
|
||||
@Player.RepeatMode
|
||||
int repeatMode =
|
||||
bundle.getInt(keyForField(FIELD_REPEAT_MODE), /* defaultValue= */ Player.REPEAT_MODE_OFF);
|
||||
int repeatMode = bundle.getInt(FIELD_REPEAT_MODE, /* defaultValue= */ Player.REPEAT_MODE_OFF);
|
||||
boolean shuffleModeEnabled =
|
||||
bundle.getBoolean(keyForField(FIELD_SHUFFLE_MODE_ENABLED), /* defaultValue= */ false);
|
||||
@Nullable Bundle timelineBundle = bundle.getBundle(keyForField(FIELD_TIMELINE));
|
||||
bundle.getBoolean(FIELD_SHUFFLE_MODE_ENABLED, /* defaultValue= */ false);
|
||||
@Nullable Bundle timelineBundle = bundle.getBundle(FIELD_TIMELINE);
|
||||
Timeline timeline =
|
||||
timelineBundle == null ? Timeline.EMPTY : Timeline.CREATOR.fromBundle(timelineBundle);
|
||||
@Nullable Bundle videoSizeBundle = bundle.getBundle(keyForField(FIELD_VIDEO_SIZE));
|
||||
@Nullable Bundle videoSizeBundle = bundle.getBundle(FIELD_VIDEO_SIZE);
|
||||
VideoSize videoSize =
|
||||
videoSizeBundle == null ? VideoSize.UNKNOWN : VideoSize.CREATOR.fromBundle(videoSizeBundle);
|
||||
@Nullable
|
||||
Bundle playlistMetadataBundle = bundle.getBundle(keyForField(FIELD_PLAYLIST_METADATA));
|
||||
@Nullable Bundle playlistMetadataBundle = bundle.getBundle(FIELD_PLAYLIST_METADATA);
|
||||
MediaMetadata playlistMetadata =
|
||||
playlistMetadataBundle == null
|
||||
? MediaMetadata.EMPTY
|
||||
: MediaMetadata.CREATOR.fromBundle(playlistMetadataBundle);
|
||||
float volume = bundle.getFloat(keyForField(FIELD_VOLUME), /* defaultValue= */ 1);
|
||||
@Nullable Bundle audioAttributesBundle = bundle.getBundle(keyForField(FIELD_AUDIO_ATTRIBUTES));
|
||||
float volume = bundle.getFloat(FIELD_VOLUME, /* defaultValue= */ 1);
|
||||
@Nullable Bundle audioAttributesBundle = bundle.getBundle(FIELD_AUDIO_ATTRIBUTES);
|
||||
AudioAttributes audioAttributes =
|
||||
audioAttributesBundle == null
|
||||
? AudioAttributes.DEFAULT
|
||||
: AudioAttributes.CREATOR.fromBundle(audioAttributesBundle);
|
||||
@Nullable Bundle cueGroupBundle = bundle.getBundle(keyForField(FIELD_CUE_GROUP));
|
||||
@Nullable Bundle cueGroupBundle = bundle.getBundle(FIELD_CUE_GROUP);
|
||||
CueGroup cueGroup =
|
||||
cueGroupBundle == null
|
||||
? CueGroup.EMPTY_TIME_ZERO
|
||||
: CueGroup.CREATOR.fromBundle(cueGroupBundle);
|
||||
@Nullable Bundle deviceInfoBundle = bundle.getBundle(keyForField(FIELD_DEVICE_INFO));
|
||||
@Nullable Bundle deviceInfoBundle = bundle.getBundle(FIELD_DEVICE_INFO);
|
||||
DeviceInfo deviceInfo =
|
||||
deviceInfoBundle == null
|
||||
? DeviceInfo.UNKNOWN
|
||||
: DeviceInfo.CREATOR.fromBundle(deviceInfoBundle);
|
||||
int deviceVolume = bundle.getInt(keyForField(FIELD_DEVICE_VOLUME), /* defaultValue= */ 0);
|
||||
boolean deviceMuted =
|
||||
bundle.getBoolean(keyForField(FIELD_DEVICE_MUTED), /* defaultValue= */ false);
|
||||
boolean playWhenReady =
|
||||
bundle.getBoolean(keyForField(FIELD_PLAY_WHEN_READY), /* defaultValue= */ false);
|
||||
int deviceVolume = bundle.getInt(FIELD_DEVICE_VOLUME, /* defaultValue= */ 0);
|
||||
boolean deviceMuted = bundle.getBoolean(FIELD_DEVICE_MUTED, /* defaultValue= */ false);
|
||||
boolean playWhenReady = bundle.getBoolean(FIELD_PLAY_WHEN_READY, /* defaultValue= */ false);
|
||||
int playWhenReadyChangedReason =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PLAY_WHEN_READY_CHANGED_REASON),
|
||||
FIELD_PLAY_WHEN_READY_CHANGED_REASON,
|
||||
/* defaultValue= */ PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST);
|
||||
@Player.PlaybackSuppressionReason
|
||||
int playbackSuppressionReason =
|
||||
bundle.getInt(
|
||||
keyForField(FIELD_PLAYBACK_SUPPRESSION_REASON),
|
||||
FIELD_PLAYBACK_SUPPRESSION_REASON,
|
||||
/* defaultValue= */ PLAYBACK_SUPPRESSION_REASON_NONE);
|
||||
@Player.State
|
||||
int playbackState =
|
||||
bundle.getInt(keyForField(FIELD_PLAYBACK_STATE), /* defaultValue= */ STATE_IDLE);
|
||||
boolean isPlaying = bundle.getBoolean(keyForField(FIELD_IS_PLAYING), /* defaultValue= */ false);
|
||||
boolean isLoading = bundle.getBoolean(keyForField(FIELD_IS_LOADING), /* defaultValue= */ false);
|
||||
@Nullable Bundle mediaMetadataBundle = bundle.getBundle(keyForField(FIELD_MEDIA_METADATA));
|
||||
int playbackState = bundle.getInt(FIELD_PLAYBACK_STATE, /* defaultValue= */ STATE_IDLE);
|
||||
boolean isPlaying = bundle.getBoolean(FIELD_IS_PLAYING, /* defaultValue= */ false);
|
||||
boolean isLoading = bundle.getBoolean(FIELD_IS_LOADING, /* defaultValue= */ false);
|
||||
@Nullable Bundle mediaMetadataBundle = bundle.getBundle(FIELD_MEDIA_METADATA);
|
||||
MediaMetadata mediaMetadata =
|
||||
mediaMetadataBundle == null
|
||||
? MediaMetadata.EMPTY
|
||||
: MediaMetadata.CREATOR.fromBundle(mediaMetadataBundle);
|
||||
long seekBackIncrementMs =
|
||||
bundle.getLong(keyForField(FIELD_SEEK_BACK_INCREMENT_MS), /* defaultValue= */ 0);
|
||||
long seekBackIncrementMs = bundle.getLong(FIELD_SEEK_BACK_INCREMENT_MS, /* defaultValue= */ 0);
|
||||
long seekForwardIncrementMs =
|
||||
bundle.getLong(keyForField(FIELD_SEEK_FORWARD_INCREMENT_MS), /* defaultValue= */ 0);
|
||||
bundle.getLong(FIELD_SEEK_FORWARD_INCREMENT_MS, /* defaultValue= */ 0);
|
||||
long maxSeekToPreviousPosition =
|
||||
bundle.getLong(keyForField(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS), /* defaultValue= */ 0);
|
||||
Bundle currentTracksBundle = bundle.getBundle(keyForField(FIELD_CURRENT_TRACKS));
|
||||
bundle.getLong(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS, /* defaultValue= */ 0);
|
||||
Bundle currentTracksBundle = bundle.getBundle(FIELD_CURRENT_TRACKS);
|
||||
Tracks currentTracks =
|
||||
currentTracksBundle == null ? Tracks.EMPTY : Tracks.CREATOR.fromBundle(currentTracksBundle);
|
||||
@Nullable
|
||||
Bundle trackSelectionParametersBundle =
|
||||
bundle.getBundle(keyForField(FIELD_TRACK_SELECTION_PARAMETERS));
|
||||
Bundle trackSelectionParametersBundle = bundle.getBundle(FIELD_TRACK_SELECTION_PARAMETERS);
|
||||
TrackSelectionParameters trackSelectionParameters =
|
||||
trackSelectionParametersBundle == null
|
||||
? TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT
|
||||
@ -1057,8 +990,4 @@ import java.lang.annotation.Target;
|
||||
currentTracks,
|
||||
trackSelectionParameters);
|
||||
}
|
||||
|
||||
private static String keyForField(@PlayerInfo.FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.Rating;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.session.MediaLibraryService.LibraryParams;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -165,24 +166,17 @@ public final class SessionCommand implements Bundleable {
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_COMMAND_CODE, FIELD_CUSTOM_ACTION, FIELD_CUSTOM_EXTRAS})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_COMMAND_CODE = 0;
|
||||
private static final int FIELD_CUSTOM_ACTION = 1;
|
||||
private static final int FIELD_CUSTOM_EXTRAS = 2;
|
||||
private static final String FIELD_COMMAND_CODE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_CUSTOM_ACTION = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_CUSTOM_EXTRAS = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_COMMAND_CODE), commandCode);
|
||||
bundle.putString(keyForField(FIELD_CUSTOM_ACTION), customAction);
|
||||
bundle.putBundle(keyForField(FIELD_CUSTOM_EXTRAS), customExtras);
|
||||
bundle.putInt(FIELD_COMMAND_CODE, commandCode);
|
||||
bundle.putString(FIELD_CUSTOM_ACTION, customAction);
|
||||
bundle.putBundle(FIELD_CUSTOM_EXTRAS, customExtras);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -191,18 +185,14 @@ public final class SessionCommand implements Bundleable {
|
||||
public static final Creator<SessionCommand> CREATOR =
|
||||
bundle -> {
|
||||
int commandCode =
|
||||
bundle.getInt(keyForField(FIELD_COMMAND_CODE), /* defaultValue= */ COMMAND_CODE_CUSTOM);
|
||||
bundle.getInt(FIELD_COMMAND_CODE, /* defaultValue= */ COMMAND_CODE_CUSTOM);
|
||||
if (commandCode != COMMAND_CODE_CUSTOM) {
|
||||
return new SessionCommand(commandCode);
|
||||
} else {
|
||||
String customAction = checkNotNull(bundle.getString(keyForField(FIELD_CUSTOM_ACTION)));
|
||||
@Nullable Bundle customExtras = bundle.getBundle(keyForField(FIELD_CUSTOM_EXTRAS));
|
||||
String customAction = checkNotNull(bundle.getString(FIELD_CUSTOM_ACTION));
|
||||
@Nullable Bundle customExtras = bundle.getBundle(FIELD_CUSTOM_EXTRAS);
|
||||
return new SessionCommand(
|
||||
customAction, customExtras == null ? Bundle.EMPTY : customExtras);
|
||||
}
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -18,22 +18,17 @@ package androidx.media3.session;
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.session.SessionCommand.COMMAND_CODE_CUSTOM;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.util.ObjectsCompat;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.session.SessionCommand.CommandCode;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -235,13 +230,7 @@ public final class SessionCommands implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_SESSION_COMMANDS})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_SESSION_COMMANDS = 0;
|
||||
private static final String FIELD_SESSION_COMMANDS = Util.intToStringMaxRadix(0);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
@ -251,7 +240,7 @@ public final class SessionCommands implements Bundleable {
|
||||
for (SessionCommand command : commands) {
|
||||
sessionCommandBundleList.add(command.toBundle());
|
||||
}
|
||||
bundle.putParcelableArrayList(keyForField(FIELD_SESSION_COMMANDS), sessionCommandBundleList);
|
||||
bundle.putParcelableArrayList(FIELD_SESSION_COMMANDS, sessionCommandBundleList);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -261,7 +250,7 @@ public final class SessionCommands implements Bundleable {
|
||||
bundle -> {
|
||||
@Nullable
|
||||
ArrayList<Bundle> sessionCommandBundleList =
|
||||
bundle.getParcelableArrayList(keyForField(FIELD_SESSION_COMMANDS));
|
||||
bundle.getParcelableArrayList(FIELD_SESSION_COMMANDS);
|
||||
if (sessionCommandBundleList == null) {
|
||||
Log.w(TAG, "Missing commands. Creating an empty SessionCommands");
|
||||
return SessionCommands.EMPTY;
|
||||
@ -273,8 +262,4 @@ public final class SessionCommands implements Bundleable {
|
||||
}
|
||||
return builder.build();
|
||||
};
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -16,19 +16,14 @@
|
||||
package androidx.media3.session;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.Player.PositionInfo;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Position information to be shared between session and controller.
|
||||
@ -162,47 +157,30 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_POSITION_INFO,
|
||||
FIELD_IS_PLAYING_AD,
|
||||
FIELD_EVENT_TIME_MS,
|
||||
FIELD_DURATION_MS,
|
||||
FIELD_BUFFERED_POSITION_MS,
|
||||
FIELD_BUFFERED_PERCENTAGE,
|
||||
FIELD_TOTAL_BUFFERED_DURATION_MS,
|
||||
FIELD_CURRENT_LIVE_OFFSET_MS,
|
||||
FIELD_CONTENT_DURATION_MS,
|
||||
FIELD_CONTENT_BUFFERED_POSITION_MS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_POSITION_INFO = 0;
|
||||
private static final int FIELD_IS_PLAYING_AD = 1;
|
||||
private static final int FIELD_EVENT_TIME_MS = 2;
|
||||
private static final int FIELD_DURATION_MS = 3;
|
||||
private static final int FIELD_BUFFERED_POSITION_MS = 4;
|
||||
private static final int FIELD_BUFFERED_PERCENTAGE = 5;
|
||||
private static final int FIELD_TOTAL_BUFFERED_DURATION_MS = 6;
|
||||
private static final int FIELD_CURRENT_LIVE_OFFSET_MS = 7;
|
||||
private static final int FIELD_CONTENT_DURATION_MS = 8;
|
||||
private static final int FIELD_CONTENT_BUFFERED_POSITION_MS = 9;
|
||||
private static final String FIELD_POSITION_INFO = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_IS_PLAYING_AD = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_EVENT_TIME_MS = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_DURATION_MS = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_BUFFERED_POSITION_MS = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_BUFFERED_PERCENTAGE = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_TOTAL_BUFFERED_DURATION_MS = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_CURRENT_LIVE_OFFSET_MS = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_CONTENT_DURATION_MS = Util.intToStringMaxRadix(8);
|
||||
private static final String FIELD_CONTENT_BUFFERED_POSITION_MS = Util.intToStringMaxRadix(9);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBundle(keyForField(FIELD_POSITION_INFO), positionInfo.toBundle());
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLAYING_AD), isPlayingAd);
|
||||
bundle.putLong(keyForField(FIELD_EVENT_TIME_MS), eventTimeMs);
|
||||
bundle.putLong(keyForField(FIELD_DURATION_MS), durationMs);
|
||||
bundle.putLong(keyForField(FIELD_BUFFERED_POSITION_MS), bufferedPositionMs);
|
||||
bundle.putInt(keyForField(FIELD_BUFFERED_PERCENTAGE), bufferedPercentage);
|
||||
bundle.putLong(keyForField(FIELD_TOTAL_BUFFERED_DURATION_MS), totalBufferedDurationMs);
|
||||
bundle.putLong(keyForField(FIELD_CURRENT_LIVE_OFFSET_MS), currentLiveOffsetMs);
|
||||
bundle.putLong(keyForField(FIELD_CONTENT_DURATION_MS), contentDurationMs);
|
||||
bundle.putLong(keyForField(FIELD_CONTENT_BUFFERED_POSITION_MS), contentBufferedPositionMs);
|
||||
bundle.putBundle(FIELD_POSITION_INFO, positionInfo.toBundle());
|
||||
bundle.putBoolean(FIELD_IS_PLAYING_AD, isPlayingAd);
|
||||
bundle.putLong(FIELD_EVENT_TIME_MS, eventTimeMs);
|
||||
bundle.putLong(FIELD_DURATION_MS, durationMs);
|
||||
bundle.putLong(FIELD_BUFFERED_POSITION_MS, bufferedPositionMs);
|
||||
bundle.putInt(FIELD_BUFFERED_PERCENTAGE, bufferedPercentage);
|
||||
bundle.putLong(FIELD_TOTAL_BUFFERED_DURATION_MS, totalBufferedDurationMs);
|
||||
bundle.putLong(FIELD_CURRENT_LIVE_OFFSET_MS, currentLiveOffsetMs);
|
||||
bundle.putLong(FIELD_CONTENT_DURATION_MS, contentDurationMs);
|
||||
bundle.putLong(FIELD_CONTENT_BUFFERED_POSITION_MS, contentBufferedPositionMs);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -210,30 +188,25 @@ import java.lang.annotation.Target;
|
||||
public static final Creator<SessionPositionInfo> CREATOR = SessionPositionInfo::fromBundle;
|
||||
|
||||
private static SessionPositionInfo fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle positionInfoBundle = bundle.getBundle(keyForField(FIELD_POSITION_INFO));
|
||||
@Nullable Bundle positionInfoBundle = bundle.getBundle(FIELD_POSITION_INFO);
|
||||
PositionInfo positionInfo =
|
||||
positionInfoBundle == null
|
||||
? DEFAULT_POSITION_INFO
|
||||
: PositionInfo.CREATOR.fromBundle(positionInfoBundle);
|
||||
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);
|
||||
boolean isPlayingAd = bundle.getBoolean(FIELD_IS_PLAYING_AD, /* defaultValue= */ false);
|
||||
long eventTimeMs = bundle.getLong(FIELD_EVENT_TIME_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long durationMs = bundle.getLong(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);
|
||||
bundle.getLong(FIELD_BUFFERED_POSITION_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
int bufferedPercentage = bundle.getInt(FIELD_BUFFERED_PERCENTAGE, /* defaultValue= */ 0);
|
||||
long totalBufferedDurationMs =
|
||||
bundle.getLong(keyForField(FIELD_TOTAL_BUFFERED_DURATION_MS), /* defaultValue= */ 0);
|
||||
bundle.getLong(FIELD_TOTAL_BUFFERED_DURATION_MS, /* defaultValue= */ 0);
|
||||
long currentLiveOffsetMs =
|
||||
bundle.getLong(keyForField(FIELD_CURRENT_LIVE_OFFSET_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
bundle.getLong(FIELD_CURRENT_LIVE_OFFSET_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long contentDurationMs =
|
||||
bundle.getLong(keyForField(FIELD_CONTENT_DURATION_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
bundle.getLong(FIELD_CONTENT_DURATION_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
long contentBufferedPositionMs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_CONTENT_BUFFERED_POSITION_MS), /* defaultValue= */ C.TIME_UNSET);
|
||||
bundle.getLong(FIELD_CONTENT_BUFFERED_POSITION_MS, /* defaultValue= */ C.TIME_UNSET);
|
||||
|
||||
return new SessionPositionInfo(
|
||||
positionInfo,
|
||||
@ -247,8 +220,4 @@ import java.lang.annotation.Target;
|
||||
contentDurationMs,
|
||||
contentBufferedPositionMs);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -175,23 +176,17 @@ public final class SessionResult implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_RESULT_CODE, FIELD_EXTRAS, FIELD_COMPLETION_TIME_MS})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_RESULT_CODE = 0;
|
||||
private static final int FIELD_EXTRAS = 1;
|
||||
private static final int FIELD_COMPLETION_TIME_MS = 2;
|
||||
private static final String FIELD_RESULT_CODE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_COMPLETION_TIME_MS = Util.intToStringMaxRadix(2);
|
||||
|
||||
@UnstableApi
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_RESULT_CODE), resultCode);
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putLong(keyForField(FIELD_COMPLETION_TIME_MS), completionTimeMs);
|
||||
bundle.putInt(FIELD_RESULT_CODE, resultCode);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
bundle.putLong(FIELD_COMPLETION_TIME_MS, completionTimeMs);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -199,17 +194,10 @@ public final class SessionResult implements Bundleable {
|
||||
@UnstableApi public static final Creator<SessionResult> CREATOR = SessionResult::fromBundle;
|
||||
|
||||
private static SessionResult fromBundle(Bundle bundle) {
|
||||
int resultCode =
|
||||
bundle.getInt(keyForField(FIELD_RESULT_CODE), /* defaultValue= */ RESULT_ERROR_UNKNOWN);
|
||||
@Nullable Bundle extras = bundle.getBundle(keyForField(FIELD_EXTRAS));
|
||||
int resultCode = bundle.getInt(FIELD_RESULT_CODE, /* defaultValue= */ RESULT_ERROR_UNKNOWN);
|
||||
@Nullable Bundle extras = bundle.getBundle(FIELD_EXTRAS);
|
||||
long completionTimeMs =
|
||||
bundle.getLong(
|
||||
keyForField(FIELD_COMPLETION_TIME_MS),
|
||||
/* defaultValue= */ SystemClock.elapsedRealtime());
|
||||
bundle.getLong(FIELD_COMPLETION_TIME_MS, /* defaultValue= */ SystemClock.elapsedRealtime());
|
||||
return new SessionResult(resultCode, extras == null ? Bundle.EMPTY : extras, completionTimeMs);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import androidx.media3.common.Bundleable;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaLibraryInfo;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
@ -153,9 +154,9 @@ public final class SessionToken implements Bundleable {
|
||||
}
|
||||
|
||||
private SessionToken(Bundle bundle) {
|
||||
checkArgument(bundle.containsKey(keyForField(FIELD_IMPL_TYPE)), "Impl type needs to be set.");
|
||||
@SessionTokenImplType int implType = bundle.getInt(keyForField(FIELD_IMPL_TYPE));
|
||||
Bundle implBundle = checkNotNull(bundle.getBundle(keyForField(FIELD_IMPL)));
|
||||
checkArgument(bundle.containsKey(FIELD_IMPL_TYPE), "Impl type needs to be set.");
|
||||
@SessionTokenImplType int implType = bundle.getInt(FIELD_IMPL_TYPE);
|
||||
Bundle implBundle = checkNotNull(bundle.getBundle(FIELD_IMPL));
|
||||
if (implType == IMPL_TYPE_BASE) {
|
||||
impl = SessionTokenImplBase.CREATOR.fromBundle(implBundle);
|
||||
} else {
|
||||
@ -481,14 +482,8 @@ public final class SessionToken implements Bundleable {
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({FIELD_IMPL_TYPE, FIELD_IMPL})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_IMPL_TYPE = 0;
|
||||
private static final int FIELD_IMPL = 1;
|
||||
private static final String FIELD_IMPL_TYPE = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_IMPL = Util.intToStringMaxRadix(1);
|
||||
|
||||
/** Types of {@link SessionTokenImpl} */
|
||||
@Documented
|
||||
@ -505,11 +500,11 @@ public final class SessionToken implements Bundleable {
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
if (impl instanceof SessionTokenImplBase) {
|
||||
bundle.putInt(keyForField(FIELD_IMPL_TYPE), IMPL_TYPE_BASE);
|
||||
bundle.putInt(FIELD_IMPL_TYPE, IMPL_TYPE_BASE);
|
||||
} else {
|
||||
bundle.putInt(keyForField(FIELD_IMPL_TYPE), IMPL_TYPE_LEGACY);
|
||||
bundle.putInt(FIELD_IMPL_TYPE, IMPL_TYPE_LEGACY);
|
||||
}
|
||||
bundle.putBundle(keyForField(FIELD_IMPL), impl.toBundle());
|
||||
bundle.putBundle(FIELD_IMPL, impl.toBundle());
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -519,8 +514,4 @@ public final class SessionToken implements Bundleable {
|
||||
private static SessionToken fromBundle(Bundle bundle) {
|
||||
return new SessionToken(bundle);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -18,21 +18,15 @@ package androidx.media3.session;
|
||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotEmpty;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.BundleCompat;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/* package */ final class SessionTokenImplBase implements SessionToken.SessionTokenImpl {
|
||||
|
||||
@ -211,45 +205,29 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_UID,
|
||||
FIELD_TYPE,
|
||||
FIELD_LIBRARY_VERSION,
|
||||
FIELD_PACKAGE_NAME,
|
||||
FIELD_SERVICE_NAME,
|
||||
FIELD_ISESSION,
|
||||
FIELD_COMPONENT_NAME,
|
||||
FIELD_EXTRAS,
|
||||
FIELD_INTERFACE_VERSION
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_UID = 0;
|
||||
private static final int FIELD_TYPE = 1;
|
||||
private static final int FIELD_LIBRARY_VERSION = 2;
|
||||
private static final int FIELD_PACKAGE_NAME = 3;
|
||||
private static final int FIELD_SERVICE_NAME = 4;
|
||||
private static final int FIELD_COMPONENT_NAME = 5;
|
||||
private static final int FIELD_ISESSION = 6;
|
||||
private static final int FIELD_EXTRAS = 7;
|
||||
private static final int FIELD_INTERFACE_VERSION = 8;
|
||||
private static final String FIELD_UID = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_TYPE = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_LIBRARY_VERSION = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_PACKAGE_NAME = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_SERVICE_NAME = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_COMPONENT_NAME = Util.intToStringMaxRadix(5);
|
||||
private static final String FIELD_ISESSION = Util.intToStringMaxRadix(6);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(7);
|
||||
private static final String FIELD_INTERFACE_VERSION = Util.intToStringMaxRadix(8);
|
||||
// Next field key = 9
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(keyForField(FIELD_UID), uid);
|
||||
bundle.putInt(keyForField(FIELD_TYPE), type);
|
||||
bundle.putInt(keyForField(FIELD_LIBRARY_VERSION), libraryVersion);
|
||||
bundle.putString(keyForField(FIELD_PACKAGE_NAME), packageName);
|
||||
bundle.putString(keyForField(FIELD_SERVICE_NAME), serviceName);
|
||||
BundleCompat.putBinder(bundle, keyForField(FIELD_ISESSION), iSession);
|
||||
bundle.putParcelable(keyForField(FIELD_COMPONENT_NAME), componentName);
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putInt(keyForField(FIELD_INTERFACE_VERSION), interfaceVersion);
|
||||
bundle.putInt(FIELD_UID, uid);
|
||||
bundle.putInt(FIELD_TYPE, type);
|
||||
bundle.putInt(FIELD_LIBRARY_VERSION, libraryVersion);
|
||||
bundle.putString(FIELD_PACKAGE_NAME, packageName);
|
||||
bundle.putString(FIELD_SERVICE_NAME, serviceName);
|
||||
BundleCompat.putBinder(bundle, FIELD_ISESSION, iSession);
|
||||
bundle.putParcelable(FIELD_COMPONENT_NAME, componentName);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
bundle.putInt(FIELD_INTERFACE_VERSION, interfaceVersion);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -257,20 +235,18 @@ import java.lang.annotation.Target;
|
||||
public static final Creator<SessionTokenImplBase> CREATOR = SessionTokenImplBase::fromBundle;
|
||||
|
||||
private static SessionTokenImplBase fromBundle(Bundle bundle) {
|
||||
checkArgument(bundle.containsKey(keyForField(FIELD_UID)), "uid should be set.");
|
||||
int uid = bundle.getInt(keyForField(FIELD_UID));
|
||||
checkArgument(bundle.containsKey(keyForField(FIELD_TYPE)), "type should be set.");
|
||||
int type = bundle.getInt(keyForField(FIELD_TYPE));
|
||||
int libraryVersion = bundle.getInt(keyForField(FIELD_LIBRARY_VERSION), /* defaultValue= */ 0);
|
||||
int interfaceVersion =
|
||||
bundle.getInt(keyForField(FIELD_INTERFACE_VERSION), /* defaultValue= */ 0);
|
||||
checkArgument(bundle.containsKey(FIELD_UID), "uid should be set.");
|
||||
int uid = bundle.getInt(FIELD_UID);
|
||||
checkArgument(bundle.containsKey(FIELD_TYPE), "type should be set.");
|
||||
int type = bundle.getInt(FIELD_TYPE);
|
||||
int libraryVersion = bundle.getInt(FIELD_LIBRARY_VERSION, /* defaultValue= */ 0);
|
||||
int interfaceVersion = bundle.getInt(FIELD_INTERFACE_VERSION, /* defaultValue= */ 0);
|
||||
String packageName =
|
||||
checkNotEmpty(
|
||||
bundle.getString(keyForField(FIELD_PACKAGE_NAME)), "package name should be set.");
|
||||
String serviceName = bundle.getString(keyForField(FIELD_SERVICE_NAME), /* defaultValue= */ "");
|
||||
@Nullable IBinder iSession = BundleCompat.getBinder(bundle, keyForField(FIELD_ISESSION));
|
||||
@Nullable ComponentName componentName = bundle.getParcelable(keyForField(FIELD_COMPONENT_NAME));
|
||||
@Nullable Bundle extras = bundle.getBundle(keyForField(FIELD_EXTRAS));
|
||||
checkNotEmpty(bundle.getString(FIELD_PACKAGE_NAME), "package name should be set.");
|
||||
String serviceName = bundle.getString(FIELD_SERVICE_NAME, /* defaultValue= */ "");
|
||||
@Nullable IBinder iSession = BundleCompat.getBinder(bundle, FIELD_ISESSION);
|
||||
@Nullable ComponentName componentName = bundle.getParcelable(FIELD_COMPONENT_NAME);
|
||||
@Nullable Bundle extras = bundle.getBundle(FIELD_EXTRAS);
|
||||
return new SessionTokenImplBase(
|
||||
uid,
|
||||
type,
|
||||
@ -282,8 +258,4 @@ import java.lang.annotation.Target;
|
||||
iSession,
|
||||
extras == null ? Bundle.EMPTY : extras);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
@ -22,20 +22,14 @@ import static androidx.media3.session.SessionToken.TYPE_BROWSER_SERVICE_LEGACY;
|
||||
import static androidx.media3.session.SessionToken.TYPE_LIBRARY_SERVICE;
|
||||
import static androidx.media3.session.SessionToken.TYPE_SESSION;
|
||||
import static androidx.media3.session.SessionToken.TYPE_SESSION_LEGACY;
|
||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.media.session.MediaSessionCompat;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.session.SessionToken.SessionTokenImpl;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/* package */ final class SessionTokenImplLegacy implements SessionTokenImpl {
|
||||
|
||||
@ -176,36 +170,22 @@ import java.lang.annotation.Target;
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(TYPE_USE)
|
||||
@IntDef({
|
||||
FIELD_LEGACY_TOKEN,
|
||||
FIELD_UID,
|
||||
FIELD_TYPE,
|
||||
FIELD_COMPONENT_NAME,
|
||||
FIELD_PACKAGE_NAME,
|
||||
FIELD_EXTRAS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_LEGACY_TOKEN = 0;
|
||||
private static final int FIELD_UID = 1;
|
||||
private static final int FIELD_TYPE = 2;
|
||||
private static final int FIELD_COMPONENT_NAME = 3;
|
||||
private static final int FIELD_PACKAGE_NAME = 4;
|
||||
private static final int FIELD_EXTRAS = 5;
|
||||
private static final String FIELD_LEGACY_TOKEN = Util.intToStringMaxRadix(0);
|
||||
private static final String FIELD_UID = Util.intToStringMaxRadix(1);
|
||||
private static final String FIELD_TYPE = Util.intToStringMaxRadix(2);
|
||||
private static final String FIELD_COMPONENT_NAME = Util.intToStringMaxRadix(3);
|
||||
private static final String FIELD_PACKAGE_NAME = Util.intToStringMaxRadix(4);
|
||||
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(5);
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBundle(
|
||||
keyForField(FIELD_LEGACY_TOKEN), legacyToken == null ? null : legacyToken.toBundle());
|
||||
bundle.putInt(keyForField(FIELD_UID), uid);
|
||||
bundle.putInt(keyForField(FIELD_TYPE), type);
|
||||
bundle.putParcelable(keyForField(FIELD_COMPONENT_NAME), componentName);
|
||||
bundle.putString(keyForField(FIELD_PACKAGE_NAME), packageName);
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
bundle.putBundle(FIELD_LEGACY_TOKEN, legacyToken == null ? null : legacyToken.toBundle());
|
||||
bundle.putInt(FIELD_UID, uid);
|
||||
bundle.putInt(FIELD_TYPE, type);
|
||||
bundle.putParcelable(FIELD_COMPONENT_NAME, componentName);
|
||||
bundle.putString(FIELD_PACKAGE_NAME, packageName);
|
||||
bundle.putBundle(FIELD_EXTRAS, extras);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -213,24 +193,19 @@ import java.lang.annotation.Target;
|
||||
public static final Creator<SessionTokenImplLegacy> CREATOR = SessionTokenImplLegacy::fromBundle;
|
||||
|
||||
private static SessionTokenImplLegacy fromBundle(Bundle bundle) {
|
||||
@Nullable Bundle legacyTokenBundle = bundle.getBundle(keyForField(FIELD_LEGACY_TOKEN));
|
||||
@Nullable Bundle legacyTokenBundle = bundle.getBundle(FIELD_LEGACY_TOKEN);
|
||||
@Nullable
|
||||
MediaSessionCompat.Token legacyToken =
|
||||
legacyTokenBundle == null ? null : MediaSessionCompat.Token.fromBundle(legacyTokenBundle);
|
||||
checkArgument(bundle.containsKey(keyForField(FIELD_UID)), "uid should be set.");
|
||||
int uid = bundle.getInt(keyForField(FIELD_UID));
|
||||
checkArgument(bundle.containsKey(keyForField(FIELD_TYPE)), "type should be set.");
|
||||
int type = bundle.getInt(keyForField(FIELD_TYPE));
|
||||
@Nullable ComponentName componentName = bundle.getParcelable(keyForField(FIELD_COMPONENT_NAME));
|
||||
checkArgument(bundle.containsKey(FIELD_UID), "uid should be set.");
|
||||
int uid = bundle.getInt(FIELD_UID);
|
||||
checkArgument(bundle.containsKey(FIELD_TYPE), "type should be set.");
|
||||
int type = bundle.getInt(FIELD_TYPE);
|
||||
@Nullable ComponentName componentName = bundle.getParcelable(FIELD_COMPONENT_NAME);
|
||||
String packageName =
|
||||
checkNotEmpty(
|
||||
bundle.getString(keyForField(FIELD_PACKAGE_NAME)), "package name should be set.");
|
||||
@Nullable Bundle extras = bundle.getBundle(keyForField(FIELD_EXTRAS));
|
||||
checkNotEmpty(bundle.getString(FIELD_PACKAGE_NAME), "package name should be set.");
|
||||
@Nullable Bundle extras = bundle.getBundle(FIELD_EXTRAS);
|
||||
return new SessionTokenImplLegacy(
|
||||
legacyToken, uid, type, componentName, packageName, extras == null ? Bundle.EMPTY : extras);
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user