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 51df3f0818..7acd4863ab 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 @@ -429,17 +429,16 @@ public abstract class Timeline implements Bundleable { private static final String FIELD_POSITION_IN_FIRST_PERIOD_US = Util.intToStringMaxRadix(13); /** - * Returns a {@link Bundle} representing the information stored in this object. + * {@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}. - * - * @param excludeMediaItem Whether to exclude {@link #mediaItem} of window. */ - public Bundle toBundle(boolean excludeMediaItem) { + @Override + public Bundle toBundle() { Bundle bundle = new Bundle(); - if (!excludeMediaItem) { + if (!MediaItem.EMPTY.equals(mediaItem)) { bundle.putBundle(FIELD_MEDIA_ITEM, mediaItem.toBundle()); } if (presentationStartTimeMs != C.TIME_UNSET) { @@ -483,19 +482,6 @@ 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}. * @@ -1384,17 +1370,14 @@ 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.
*/
- public final Bundle toBundle(boolean excludeMediaItems) {
+ @Override
+ public final Bundle toBundle() {
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}.
*
diff --git a/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java b/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java
index 57fffe609e..4d8e305f2c 100644
--- a/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java
+++ b/library/common/src/test/java/com/google/android/exoplayer2/TimelineTest.java
@@ -351,10 +351,8 @@ public class TimelineTest {
Bundle windowBundle = window.toBundle();
- // Check that default values are skipped when bundling. MediaItem key is not added to the bundle
- // only when excludeMediaItem is true.
- assertThat(windowBundle.keySet()).hasSize(1);
- assertThat(window.toBundle(/* excludeMediaItem= */ true).keySet()).isEmpty();
+ // Check that default values are skipped when bundling.
+ assertThat(windowBundle.keySet()).isEmpty();
Timeline.Window restoredWindow = Timeline.Window.CREATOR.fromBundle(windowBundle);