Commit 5e9c9ed2 by tonihei Committed by christosts

Extend command GET_CURRENT_MEDIA_ITEM to more methods.

We currently only document it for the getCurrentMediaItem(), but
the command was always meant to cover all information about the
current media item and the position therein.

To correctly hide information for controllers, we need to filter
the Timeline when bundling the PlayerInfo class if only this
command is available.

PiperOrigin-RevId: 503098124
parent 45596fcd
...@@ -1627,10 +1627,28 @@ public interface Player { ...@@ -1627,10 +1627,28 @@ public interface Player {
int COMMAND_SET_REPEAT_MODE = 15; int COMMAND_SET_REPEAT_MODE = 15;
/** /**
* Command to get the currently playing {@link MediaItem}. * Command to get information about the currently playing {@link MediaItem}.
* *
* <p>The {@link #getCurrentMediaItem()} method must only be called if this command is {@linkplain * <p>The following methods must only be called if this command is {@linkplain
* #isCommandAvailable(int) available}. * #isCommandAvailable(int) available}:
*
* <ul>
* <li>{@link #getCurrentMediaItem()}
* <li>{@link #isCurrentMediaItemDynamic()}
* <li>{@link #isCurrentMediaItemLive()}
* <li>{@link #isCurrentMediaItemSeekable()}
* <li>{@link #getCurrentLiveOffset()}
* <li>{@link #getDuration()}
* <li>{@link #getCurrentPosition()}
* <li>{@link #getBufferedPosition()}
* <li>{@link #getContentDuration()}
* <li>{@link #getContentPosition()}
* <li>{@link #getContentBufferedPosition()}
* <li>{@link #getTotalBufferedDuration()}
* <li>{@link #isPlayingAd()}
* <li>{@link #getCurrentAdGroupIndex()}
* <li>{@link #getCurrentAdIndexInAdGroup()}
* </ul>
*/ */
int COMMAND_GET_CURRENT_MEDIA_ITEM = 16; int COMMAND_GET_CURRENT_MEDIA_ITEM = 16;
...@@ -1650,8 +1668,6 @@ public interface Player { ...@@ -1650,8 +1668,6 @@ public interface Player {
* <li>{@link #getPreviousMediaItemIndex()} * <li>{@link #getPreviousMediaItemIndex()}
* <li>{@link #hasPreviousMediaItem()} * <li>{@link #hasPreviousMediaItem()}
* <li>{@link #hasNextMediaItem()} * <li>{@link #hasNextMediaItem()}
* <li>{@link #getCurrentAdGroupIndex()}
* <li>{@link #getCurrentAdIndexInAdGroup()}
* </ul> * </ul>
*/ */
int COMMAND_GET_TIMELINE = 17; int COMMAND_GET_TIMELINE = 17;
...@@ -2681,18 +2697,27 @@ public interface Player { ...@@ -2681,18 +2697,27 @@ public interface Player {
/** /**
* Returns the duration of the current content or ad in milliseconds, or {@link C#TIME_UNSET} if * Returns the duration of the current content or ad in milliseconds, or {@link C#TIME_UNSET} if
* the duration is not known. * the duration is not known.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getDuration(); long getDuration();
/** /**
* Returns the playback position in the current content or ad, in milliseconds, or the prospective * Returns the playback position in the current content or ad, in milliseconds, or the prospective
* position in milliseconds if the {@link #getCurrentTimeline() current timeline} is empty. * position in milliseconds if the {@link #getCurrentTimeline() current timeline} is empty.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getCurrentPosition(); long getCurrentPosition();
/** /**
* Returns an estimate of the position in the current content or ad up to which data is buffered, * Returns an estimate of the position in the current content or ad up to which data is buffered,
* in milliseconds. * in milliseconds.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getBufferedPosition(); long getBufferedPosition();
...@@ -2706,6 +2731,9 @@ public interface Player { ...@@ -2706,6 +2731,9 @@ public interface Player {
/** /**
* Returns an estimate of the total buffered duration from the current position, in milliseconds. * Returns an estimate of the total buffered duration from the current position, in milliseconds.
* This includes pre-buffered data for subsequent ads and {@linkplain MediaItem media items}. * This includes pre-buffered data for subsequent ads and {@linkplain MediaItem media items}.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getTotalBufferedDuration(); long getTotalBufferedDuration();
...@@ -2719,6 +2747,9 @@ public interface Player { ...@@ -2719,6 +2747,9 @@ public interface Player {
* Returns whether the current {@link MediaItem} is dynamic (may change when the {@link Timeline} * Returns whether the current {@link MediaItem} is dynamic (may change when the {@link Timeline}
* is updated), or {@code false} if the {@link Timeline} is empty. * is updated), or {@code false} if the {@link Timeline} is empty.
* *
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*
* @see Timeline.Window#isDynamic * @see Timeline.Window#isDynamic
*/ */
boolean isCurrentMediaItemDynamic(); boolean isCurrentMediaItemDynamic();
...@@ -2733,6 +2764,9 @@ public interface Player { ...@@ -2733,6 +2764,9 @@ public interface Player {
* Returns whether the current {@link MediaItem} is live, or {@code false} if the {@link Timeline} * Returns whether the current {@link MediaItem} is live, or {@code false} if the {@link Timeline}
* is empty. * is empty.
* *
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*
* @see Timeline.Window#isLive() * @see Timeline.Window#isLive()
*/ */
boolean isCurrentMediaItemLive(); boolean isCurrentMediaItemLive();
...@@ -2747,6 +2781,9 @@ public interface Player { ...@@ -2747,6 +2781,9 @@ public interface Player {
* *
* <p>Note that this offset may rely on an accurate local time, so this method may return an * <p>Note that this offset may rely on an accurate local time, so this method may return an
* incorrect value if the difference between system clock and server clock is unknown. * incorrect value if the difference between system clock and server clock is unknown.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getCurrentLiveOffset(); long getCurrentLiveOffset();
...@@ -2760,18 +2797,26 @@ public interface Player { ...@@ -2760,18 +2797,26 @@ public interface Player {
* Returns whether the current {@link MediaItem} is seekable, or {@code false} if the {@link * Returns whether the current {@link MediaItem} is seekable, or {@code false} if the {@link
* Timeline} is empty. * Timeline} is empty.
* *
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*
* @see Timeline.Window#isSeekable * @see Timeline.Window#isSeekable
*/ */
boolean isCurrentMediaItemSeekable(); boolean isCurrentMediaItemSeekable();
/** Returns whether the player is currently playing an ad. */ /**
* Returns whether the player is currently playing an ad.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/
boolean isPlayingAd(); boolean isPlayingAd();
/** /**
* If {@link #isPlayingAd()} returns true, returns the index of the ad group in the period * If {@link #isPlayingAd()} returns true, returns the index of the ad group in the period
* currently being played. Returns {@link C#INDEX_UNSET} otherwise. * currently being played. Returns {@link C#INDEX_UNSET} otherwise.
* *
* <p>This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain * <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}. * #getAvailableCommands() available}.
*/ */
int getCurrentAdGroupIndex(); int getCurrentAdGroupIndex();
...@@ -2780,7 +2825,7 @@ public interface Player { ...@@ -2780,7 +2825,7 @@ public interface Player {
* If {@link #isPlayingAd()} returns true, returns the index of the ad in its ad group. Returns * If {@link #isPlayingAd()} returns true, returns the index of the ad in its ad group. Returns
* {@link C#INDEX_UNSET} otherwise. * {@link C#INDEX_UNSET} otherwise.
* *
* <p>This method must only be called if {@link #COMMAND_GET_TIMELINE} is {@linkplain * <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}. * #getAvailableCommands() available}.
*/ */
int getCurrentAdIndexInAdGroup(); int getCurrentAdIndexInAdGroup();
...@@ -2789,6 +2834,9 @@ public interface Player { ...@@ -2789,6 +2834,9 @@ public interface Player {
* If {@link #isPlayingAd()} returns {@code true}, returns the duration of the current content in * If {@link #isPlayingAd()} returns {@code true}, returns the duration of the current content in
* milliseconds, or {@link C#TIME_UNSET} if the duration is not known. If there is no ad playing, * milliseconds, or {@link C#TIME_UNSET} if the duration is not known. If there is no ad playing,
* the returned duration is the same as that returned by {@link #getDuration()}. * the returned duration is the same as that returned by {@link #getDuration()}.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getContentDuration(); long getContentDuration();
...@@ -2796,6 +2844,9 @@ public interface Player { ...@@ -2796,6 +2844,9 @@ public interface Player {
* If {@link #isPlayingAd()} returns {@code true}, returns the content position that will be * If {@link #isPlayingAd()} returns {@code true}, returns the content position that will be
* played once all ads in the ad group have finished playing, in milliseconds. If there is no ad * played once all ads in the ad group have finished playing, in milliseconds. If there is no ad
* playing, the returned position is the same as that returned by {@link #getCurrentPosition()}. * playing, the returned position is the same as that returned by {@link #getCurrentPosition()}.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getContentPosition(); long getContentPosition();
...@@ -2803,6 +2854,9 @@ public interface Player { ...@@ -2803,6 +2854,9 @@ public interface Player {
* If {@link #isPlayingAd()} returns {@code true}, returns an estimate of the content position in * If {@link #isPlayingAd()} returns {@code true}, returns an estimate of the content position in
* the current content up to which data is buffered, in milliseconds. If there is no ad playing, * the current content up to which data is buffered, in milliseconds. If there is no ad playing,
* the returned position is the same as that returned by {@link #getBufferedPosition()}. * the returned position is the same as that returned by {@link #getBufferedPosition()}.
*
* <p>This method must only be called if {@link #COMMAND_GET_CURRENT_MEDIA_ITEM} is {@linkplain
* #getAvailableCommands() available}.
*/ */
long getContentBufferedPosition(); long getContentBufferedPosition();
......
...@@ -1405,6 +1405,38 @@ public abstract class Timeline implements Bundleable { ...@@ -1405,6 +1405,38 @@ public abstract class Timeline implements Bundleable {
} }
/** /**
* Returns a {@link Bundle} containing just the specified {@link Window}.
*
* <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 windowIndex The index of the {@link Window} to include in the {@link Bundle}.
*/
public final Bundle toBundleWithOneWindowOnly(int windowIndex) {
Window window = getWindow(windowIndex, new Window(), /* defaultPositionProjectionUs= */ 0);
List<Bundle> periodBundles = new ArrayList<>();
Period period = new Period();
for (int i = window.firstPeriodIndex; i <= window.lastPeriodIndex; i++) {
getPeriod(i, period, /* setIds= */ false);
period.windowIndex = 0;
periodBundles.add(period.toBundle());
}
window.lastPeriodIndex = window.lastPeriodIndex - window.firstPeriodIndex;
window.firstPeriodIndex = 0;
Bundle windowBundle = window.toBundle();
Bundle bundle = new Bundle();
BundleUtil.putBinder(
bundle, FIELD_WINDOWS, new BundleListRetriever(ImmutableList.of(windowBundle)));
BundleUtil.putBinder(bundle, FIELD_PERIODS, new BundleListRetriever(periodBundles));
bundle.putIntArray(FIELD_SHUFFLED_WINDOW_INDICES, new int[] {0});
return bundle;
}
/**
* 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