use of androidx.media3.common.BundleListRetriever in project media by androidx.
the class LibraryResult method toBundle.
@UnstableApi
@Override
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putInt(keyForField(FIELD_RESULT_CODE), resultCode);
bundle.putLong(keyForField(FIELD_COMPLETION_TIME_MS), completionTimeMs);
bundle.putBundle(keyForField(FIELD_PARAMS), BundleableUtil.toNullableBundle(params));
bundle.putInt(keyForField(FIELD_VALUE_TYPE), valueType);
if (value == null) {
return bundle;
}
switch(valueType) {
case VALUE_TYPE_ITEM:
bundle.putBundle(keyForField(FIELD_VALUE), BundleableUtil.toNullableBundle((MediaItem) value));
break;
case VALUE_TYPE_ITEM_LIST:
BundleCompat.putBinder(bundle, keyForField(FIELD_VALUE), new BundleListRetriever(BundleableUtil.toBundleList((ImmutableList<MediaItem>) value)));
break;
case VALUE_TYPE_VOID:
case VALUE_TYPE_ERROR:
// value must be null for both these types, so we should have returned above.
throw new IllegalStateException();
}
return bundle;
}
use of androidx.media3.common.BundleListRetriever in project media by androidx.
the class Timeline method toBundle.
/**
* {@inheritDoc}
*
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of
* an instance restored by {@link #CREATOR} may have missing fields as described in {@link
* Window#toBundle()} and {@link Period#toBundle()}.
*
* @param excludeMediaItems Whether to exclude all {@link Window#mediaItem media items} of windows
* in the timeline.
*/
@UnstableApi
public final Bundle toBundle(boolean excludeMediaItems) {
List<Bundle> windowBundles = new ArrayList<>();
int windowCount = getWindowCount();
Window window = new Window();
for (int i = 0; i < windowCount; i++) {
windowBundles.add(getWindow(i, window, /* defaultPositionProjectionUs= */
0).toBundle(excludeMediaItems));
}
List<Bundle> periodBundles = new ArrayList<>();
int periodCount = getPeriodCount();
Period period = new Period();
for (int i = 0; i < periodCount; i++) {
periodBundles.add(getPeriod(i, period, /* setIds= */
false).toBundle());
}
int[] shuffledWindowIndices = new int[windowCount];
if (windowCount > 0) {
shuffledWindowIndices[0] = getFirstWindowIndex(/* shuffleModeEnabled= */
true);
}
for (int i = 1; i < windowCount; i++) {
shuffledWindowIndices[i] = getNextWindowIndex(shuffledWindowIndices[i - 1], Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */
true);
}
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);
return bundle;
}
Aggregations