Commit 581e543d by jinpark Committed by Oliver Woodman

Add toBundle(boolean excludeMediaItems) to Timeline.

Add MediaItem.EMPTY.

PiperOrigin-RevId: 379273172
parent 8777146e
...@@ -1203,6 +1203,9 @@ public final class MediaItem implements Bundleable { ...@@ -1203,6 +1203,9 @@ public final class MediaItem implements Bundleable {
*/ */
public static final String DEFAULT_MEDIA_ID = ""; public static final String DEFAULT_MEDIA_ID = "";
/** Empty {@link MediaItem}. */
public static final MediaItem EMPTY = new MediaItem.Builder().build();
/** Identifies the media item. */ /** Identifies the media item. */
public final String mediaId; public final String mediaId;
......
...@@ -440,18 +440,11 @@ public abstract class Timeline implements Bundleable { ...@@ -440,18 +440,11 @@ public abstract class Timeline implements Bundleable {
private static final int FIELD_LAST_PERIOD_INDEX = 12; private static final int FIELD_LAST_PERIOD_INDEX = 12;
private static final int FIELD_POSITION_IN_FIRST_PERIOD_US = 13; private static final int FIELD_POSITION_IN_FIRST_PERIOD_US = 13;
/** private final Bundle toBundle(boolean excludeMediaItem) {
* {@inheritDoc}
*
* <p>It omits the {@link #uid} and {@link #manifest} fields. The {@link #uid} of an instance
* restored by {@link #CREATOR} will be a fake {@link Object} and the {@link #manifest} of the
* instance will be {@code null}.
*/
// TODO(b/166765820): See if missing fields would be okay and add them to the Bundle otherwise.
@Override
public Bundle toBundle() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBundle(keyForField(FIELD_MEDIA_ITEM), mediaItem.toBundle()); bundle.putBundle(
keyForField(FIELD_MEDIA_ITEM),
excludeMediaItem ? MediaItem.EMPTY.toBundle() : mediaItem.toBundle());
bundle.putLong(keyForField(FIELD_PRESENTATION_START_TIME_MS), presentationStartTimeMs); bundle.putLong(keyForField(FIELD_PRESENTATION_START_TIME_MS), presentationStartTimeMs);
bundle.putLong(keyForField(FIELD_WINDOW_START_TIME_MS), windowStartTimeMs); bundle.putLong(keyForField(FIELD_WINDOW_START_TIME_MS), windowStartTimeMs);
bundle.putLong( bundle.putLong(
...@@ -472,6 +465,19 @@ public abstract class Timeline implements Bundleable { ...@@ -472,6 +465,19 @@ public abstract class Timeline implements Bundleable {
} }
/** /**
* {@inheritDoc}
*
* <p>It omits the {@link #uid} and {@link #manifest} fields. The {@link #uid} of an instance
* restored by {@link #CREATOR} will be a fake {@link Object} and the {@link #manifest} of the
* instance will be {@code null}.
*/
// TODO(b/166765820): See if missing fields would be okay and add them to the Bundle otherwise.
@Override
public Bundle toBundle() {
return toBundle(/* excludeMediaItem= */ false);
}
/**
* Object that can restore {@link Period} from a {@link Bundle}. * Object that can restore {@link Period} from a {@link Bundle}.
* *
* <p>The {@link #uid} of a restored instance will be a fake {@link Object} and the {@link * <p>The {@link #uid} of a restored instance will be a fake {@link Object} and the {@link
...@@ -1309,14 +1315,17 @@ public abstract class Timeline implements Bundleable { ...@@ -1309,14 +1315,17 @@ public abstract class Timeline implements Bundleable {
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of * <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 * an instance restored by {@link #CREATOR} may have missing fields as described in {@link
* Window#toBundle()} and {@link Period#toBundle()}. * Window#toBundle()} and {@link Period#toBundle()}.
*
* @param excludeMediaItems Whether to exclude all {@link Window#mediaItem media items} of windows
* in the timeline.
*/ */
@Override public final Bundle toBundle(boolean excludeMediaItems) {
public final Bundle toBundle() {
List<Bundle> windowBundles = new ArrayList<>(); List<Bundle> windowBundles = new ArrayList<>();
int windowCount = getWindowCount(); int windowCount = getWindowCount();
Window window = new Window(); Window window = new Window();
for (int i = 0; i < windowCount; i++) { for (int i = 0; i < windowCount; i++) {
windowBundles.add(getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle()); windowBundles.add(
getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle(excludeMediaItems));
} }
List<Bundle> periodBundles = new ArrayList<>(); List<Bundle> periodBundles = new ArrayList<>();
...@@ -1346,6 +1355,18 @@ public abstract class Timeline implements Bundleable { ...@@ -1346,6 +1355,18 @@ public abstract class Timeline implements Bundleable {
} }
/** /**
* {@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()}.
*/
@Override
public final Bundle toBundle() {
return toBundle(/* excludeMediaItems= */ false);
}
/**
* Object that can restore a {@link Timeline} from a {@link Bundle}. * Object that can restore a {@link Timeline} from a {@link Bundle}.
* *
* <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of * <p>The {@link #getWindow(int, Window)} windows} and {@link #getPeriod(int, Period) periods} of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment