diff --git a/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java b/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java index 0b4f7409d8..e8373532a1 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/MediaItem.java @@ -1203,6 +1203,9 @@ public final class MediaItem implements Bundleable { */ public static final String DEFAULT_MEDIA_ID = ""; + /** Empty {@link MediaItem}. */ + public static final MediaItem EMPTY = new MediaItem.Builder().build(); + /** Identifies the media item. */ public final String mediaId; diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java b/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java index d332272801..b0e153d780 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/Timeline.java @@ -440,18 +440,11 @@ public abstract class Timeline implements Bundleable { private static final int FIELD_LAST_PERIOD_INDEX = 12; private static final int FIELD_POSITION_IN_FIRST_PERIOD_US = 13; - /** - * {@inheritDoc} - * - *
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() { + private final Bundle toBundle(boolean excludeMediaItem) { 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_WINDOW_START_TIME_MS), windowStartTimeMs); bundle.putLong( @@ -471,6 +464,19 @@ public abstract class Timeline implements Bundleable { return bundle; } + /** + * {@inheritDoc} + * + *
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}. * @@ -1309,14 +1315,17 @@ public abstract class Timeline implements Bundleable { *
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.
*/
- @Override
- public final Bundle toBundle() {
+ public final Bundle toBundle(boolean excludeMediaItems) {
List 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}.
*