Class Timeline.Period

  • All Implemented Interfaces:
    Bundleable
    Enclosing class:
    Timeline

    public static final class Timeline.Period
    extends Object
    implements Bundleable
    Holds information about a period in a Timeline. A period defines a single logical piece of media, for example a media file. It may also define groups of ads inserted into the media, along with information about whether those ads have been loaded and played.

    The figure below shows some of the information defined by a period, as well as how this information relates to a corresponding Timeline.Window in the timeline.

    Information defined by a
 period

    • Constructor Summary

      Constructors 
      Constructor Description
      Period()
      Creates a new instance with no ad playback state.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(Object obj)  
      int getAdCountInAdGroup​(int adGroupIndex)
      Returns the number of ads in the ad group at index adGroupIndex, or C.LENGTH_UNSET if not yet known.
      long getAdDurationUs​(int adGroupIndex, int adIndexInAdGroup)
      Returns the duration of the ad at index adIndexInAdGroup in the ad group at adGroupIndex, in microseconds, or C.TIME_UNSET if not yet known.
      int getAdGroupCount()
      Returns the number of ad groups in the period.
      int getAdGroupIndexAfterPositionUs​(long positionUs)
      Returns the index of the next ad group after positionUs in the period that has ads that should be played.
      int getAdGroupIndexForPositionUs​(long positionUs)
      Returns the index of the ad group at or before positionUs in the period that should be played before the content at positionUs.
      long getAdGroupTimeUs​(int adGroupIndex)
      Returns the time of the ad group at index adGroupIndex in the period, in microseconds.
      long getAdResumePositionUs()
      Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.
      Object getAdsId()
      Returns the opaque identifier for ads played with this period, or null if unset.
      long getContentResumeOffsetUs​(int adGroupIndex)
      Returns the offset in microseconds which should be added to the content stream when resuming playback after the specified ad group.
      long getDurationMs()
      Returns the duration of the period in milliseconds, or C.TIME_UNSET if unknown.
      long getDurationUs()
      Returns the duration of this period in microseconds, or C.TIME_UNSET if unknown.
      int getFirstAdIndexToPlay​(int adGroupIndex)
      Returns the index of the first ad in the specified ad group that should be played, or the number of ads in the ad group if no ads should be played.
      int getNextAdIndexToPlay​(int adGroupIndex, int lastPlayedAdIndex)
      Returns the index of the next ad in the specified ad group that should be played after playing adIndexInAdGroup, or the number of ads in the ad group if no later ads should be played.
      long getPositionInWindowMs()
      Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds.
      long getPositionInWindowUs()
      Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds.
      int getRemovedAdGroupCount()
      Returns the number of removed ad groups in the period.
      int hashCode()  
      boolean hasPlayedAdGroup​(int adGroupIndex)
      Returns whether all ads in the ad group at index adGroupIndex have been played, skipped or failed.
      boolean isServerSideInsertedAdGroup​(int adGroupIndex)
      Returns whether the ad group at index adGroupIndex is server-side inserted and part of the content stream.
      Timeline.Period set​(Object id, Object uid, int windowIndex, long durationUs, long positionInWindowUs)
      Sets the data held by this period.
      Timeline.Period set​(Object id, Object uid, int windowIndex, long durationUs, long positionInWindowUs, AdPlaybackState adPlaybackState, boolean isPlaceholder)
      Sets the data held by this period.
      Bundle toBundle()
      Returns a Bundle representing the information stored in this object.
    • Field Detail

      • id

        @Nullable
        public Object id
        An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.
      • uid

        @Nullable
        public Object uid
        A unique identifier for the period. May be null if the ids of the period are not required.
      • windowIndex

        public int windowIndex
        The index of the window to which this period belongs.
      • durationUs

        public long durationUs
        The duration of this period in microseconds, or C.TIME_UNSET if unknown.
      • positionInWindowUs

        public long positionInWindowUs
        The position of the start of this period relative to the start of the window to which it belongs, in microseconds. May be negative if the start of the period is not within the window.
      • isPlaceholder

        public boolean isPlaceholder
        Whether this period contains placeholder information because the real information has yet to be loaded.
    • Constructor Detail

      • Period

        public Period()
        Creates a new instance with no ad playback state.
    • Method Detail

      • set

        public Timeline.Period set​(@Nullable
                                   Object id,
                                   @Nullable
                                   Object uid,
                                   int windowIndex,
                                   long durationUs,
                                   long positionInWindowUs)
        Sets the data held by this period.
        Parameters:
        id - An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.
        uid - A unique identifier for the period. May be null if the ids of the period are not required.
        windowIndex - The index of the window to which this period belongs.
        durationUs - The duration of this period in microseconds, or C.TIME_UNSET if unknown.
        positionInWindowUs - The position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window.
        Returns:
        This period, for convenience.
      • set

        public Timeline.Period set​(@Nullable
                                   Object id,
                                   @Nullable
                                   Object uid,
                                   int windowIndex,
                                   long durationUs,
                                   long positionInWindowUs,
                                   AdPlaybackState adPlaybackState,
                                   boolean isPlaceholder)
        Sets the data held by this period.
        Parameters:
        id - An identifier for the period. Not necessarily unique. May be null if the ids of the period are not required.
        uid - A unique identifier for the period. May be null if the ids of the period are not required.
        windowIndex - The index of the window to which this period belongs.
        durationUs - The duration of this period in microseconds, or C.TIME_UNSET if unknown.
        positionInWindowUs - The position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window.
        adPlaybackState - The state of the period's ads, or AdPlaybackState.NONE if there are no ads.
        isPlaceholder - Whether this period contains placeholder information because the real information has yet to be loaded.
        Returns:
        This period, for convenience.
      • getDurationMs

        public long getDurationMs()
        Returns the duration of the period in milliseconds, or C.TIME_UNSET if unknown.
      • getDurationUs

        public long getDurationUs()
        Returns the duration of this period in microseconds, or C.TIME_UNSET if unknown.
      • getPositionInWindowMs

        public long getPositionInWindowMs()
        Returns the position of the start of this period relative to the start of the window to which it belongs, in milliseconds. May be negative if the start of the period is not within the window.
      • getPositionInWindowUs

        public long getPositionInWindowUs()
        Returns the position of the start of this period relative to the start of the window to which it belongs, in microseconds. May be negative if the start of the period is not within the window.
      • getAdsId

        @Nullable
        public Object getAdsId()
        Returns the opaque identifier for ads played with this period, or null if unset.
      • getAdGroupCount

        public int getAdGroupCount()
        Returns the number of ad groups in the period.
      • getRemovedAdGroupCount

        public int getRemovedAdGroupCount()
        Returns the number of removed ad groups in the period. Ad groups with indices between 0 (inclusive) and removedAdGroupCount (exclusive) will be empty.
      • getAdGroupTimeUs

        public long getAdGroupTimeUs​(int adGroupIndex)
        Returns the time of the ad group at index adGroupIndex in the period, in microseconds.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        The time of the ad group at the index relative to the start of the enclosing Timeline.Period, in microseconds, or C.TIME_END_OF_SOURCE for a post-roll ad group.
      • getFirstAdIndexToPlay

        public int getFirstAdIndexToPlay​(int adGroupIndex)
        Returns the index of the first ad in the specified ad group that should be played, or the number of ads in the ad group if no ads should be played.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        The index of the first ad that should be played, or the number of ads in the ad group if no ads should be played.
      • getNextAdIndexToPlay

        public int getNextAdIndexToPlay​(int adGroupIndex,
                                        int lastPlayedAdIndex)
        Returns the index of the next ad in the specified ad group that should be played after playing adIndexInAdGroup, or the number of ads in the ad group if no later ads should be played.
        Parameters:
        adGroupIndex - The ad group index.
        lastPlayedAdIndex - The last played ad index in the ad group.
        Returns:
        The index of the next ad that should be played, or the number of ads in the ad group if the ad group does not have any ads remaining to play.
      • hasPlayedAdGroup

        public boolean hasPlayedAdGroup​(int adGroupIndex)
        Returns whether all ads in the ad group at index adGroupIndex have been played, skipped or failed.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        Whether all ads in the ad group at index adGroupIndex have been played, skipped or failed.
      • getAdGroupIndexForPositionUs

        public int getAdGroupIndexForPositionUs​(long positionUs)
        Returns the index of the ad group at or before positionUs in the period that should be played before the content at positionUs. Returns C.INDEX_UNSET if the ad group at or before positionUs has no ads remaining to be played, or if there is no such ad group.
        Parameters:
        positionUs - The period position at or before which to find an ad group, in microseconds.
        Returns:
        The index of the ad group, or C.INDEX_UNSET.
      • getAdGroupIndexAfterPositionUs

        public int getAdGroupIndexAfterPositionUs​(long positionUs)
        Returns the index of the next ad group after positionUs in the period that has ads that should be played. Returns C.INDEX_UNSET if there is no such ad group.
        Parameters:
        positionUs - The period position after which to find an ad group, in microseconds.
        Returns:
        The index of the ad group, or C.INDEX_UNSET.
      • getAdCountInAdGroup

        public int getAdCountInAdGroup​(int adGroupIndex)
        Returns the number of ads in the ad group at index adGroupIndex, or C.LENGTH_UNSET if not yet known.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        The number of ads in the ad group, or C.LENGTH_UNSET if not yet known.
      • getAdDurationUs

        public long getAdDurationUs​(int adGroupIndex,
                                    int adIndexInAdGroup)
        Returns the duration of the ad at index adIndexInAdGroup in the ad group at adGroupIndex, in microseconds, or C.TIME_UNSET if not yet known.
        Parameters:
        adGroupIndex - The ad group index.
        adIndexInAdGroup - The ad index in the ad group.
        Returns:
        The duration of the ad, or C.TIME_UNSET if not yet known.
      • getAdResumePositionUs

        public long getAdResumePositionUs()
        Returns the position offset in the first unplayed ad at which to begin playback, in microseconds.
      • isServerSideInsertedAdGroup

        public boolean isServerSideInsertedAdGroup​(int adGroupIndex)
        Returns whether the ad group at index adGroupIndex is server-side inserted and part of the content stream.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        Whether this ad group is server-side inserted and part of the content stream.
      • getContentResumeOffsetUs

        public long getContentResumeOffsetUs​(int adGroupIndex)
        Returns the offset in microseconds which should be added to the content stream when resuming playback after the specified ad group.
        Parameters:
        adGroupIndex - The ad group index.
        Returns:
        The offset that should be added to the content stream, in microseconds.
      • equals

        public boolean equals​(@Nullable
                              Object obj)
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toBundle

        public Bundle toBundle()
        Returns a Bundle representing the information stored in this object.

        It omits the id and uid fields so these fields of an instance restored by CREATOR will always be null.

        Specified by:
        toBundle in interface Bundleable