mirror of
https://github.com/samsonjs/media.git
synced 2026-04-11 12:15:47 +00:00
Add toBundle(boolean excludeMediaItems) to Timeline.
Add MediaItem.EMPTY. PiperOrigin-RevId: 379273172
This commit is contained in:
parent
8777146e33
commit
581e543d39
2 changed files with 38 additions and 14 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
*
|
||||
* <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() {
|
||||
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}
|
||||
*
|
||||
* <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}.
|
||||
*
|
||||
|
|
@ -1309,14 +1315,17 @@ public abstract class Timeline implements Bundleable {
|
|||
* <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.
|
||||
*/
|
||||
@Override
|
||||
public final Bundle toBundle() {
|
||||
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());
|
||||
windowBundles.add(
|
||||
getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle(excludeMediaItems));
|
||||
}
|
||||
|
||||
List<Bundle> periodBundles = new ArrayList<>();
|
||||
|
|
@ -1345,6 +1354,18 @@ public abstract class Timeline implements Bundleable {
|
|||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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}.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue