mirror of
https://github.com/samsonjs/media.git
synced 2026-03-30 10:15:48 +00:00
Make availableCommands known when bundling PlayerInfo
When bundling PlayerInfo, we remove data when the controller is not allowed to access this data via getters. We also remove data for performance reasons. In the toBundle() method, it's currently hard to make the connection between allowed commands and filtering, because the values are checked at a different place. This can be made more readable by forwarding the applicable Commands directly. The only functional fix is to filter the Timeline when sending the first PlayerInfo after a connecting a controller if the command to get the Timeline is not available. This also allows us to remove a path to filter MediaItems from Timelines as it isn't used. PiperOrigin-RevId: 502607391
This commit is contained in:
parent
2cc64a037c
commit
5461d5cbf1
2 changed files with 9 additions and 40 deletions
|
|
@ -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}
|
||||
*
|
||||
* <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}.
|
||||
*
|
||||
* @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}
|
||||
*
|
||||
* <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}.
|
||||
*
|
||||
|
|
@ -1384,17 +1370,14 @@ 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.
|
||||
*/
|
||||
public final Bundle toBundle(boolean excludeMediaItems) {
|
||||
@Override
|
||||
public final Bundle toBundle() {
|
||||
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));
|
||||
windowBundles.add(getWindow(i, window, /* defaultPositionProjectionUs= */ 0).toBundle());
|
||||
}
|
||||
|
||||
List<Bundle> periodBundles = new ArrayList<>();
|
||||
|
|
@ -1421,18 +1404,6 @@ 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}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue