public interface MediaPeriod extends SequenceableLoader
Modifier and Type | Interface and Description |
---|---|
static interface |
MediaPeriod.Callback
A callback to be notified of
MediaPeriod events. |
Modifier and Type | Method and Description |
---|---|
boolean |
continueLoading(long positionUs)
Attempts to continue loading.
|
void |
discardBuffer(long positionUs)
Discards buffered media up to the specified position.
|
long |
getBufferedPositionUs()
Returns an estimate of the position up to which data is buffered for the enabled tracks.
|
long |
getNextLoadPositionUs()
Returns the next load time, or
C.TIME_END_OF_SOURCE if loading has finished. |
TrackGroupArray |
getTrackGroups()
Returns the
TrackGroup s exposed by the period. |
void |
maybeThrowPrepareError()
Throws an error that's preventing the period from becoming prepared.
|
void |
prepare(MediaPeriod.Callback callback)
Prepares this media period asynchronously.
|
long |
readDiscontinuity()
Attempts to read a discontinuity.
|
long |
seekToUs(long positionUs)
Attempts to seek to the specified position in microseconds.
|
long |
selectTracks(TrackSelection[] selections,
boolean[] mayRetainStreamFlags,
SampleStream[] streams,
boolean[] streamResetFlags,
long positionUs)
Performs a track selection.
|
void prepare(MediaPeriod.Callback callback)
callback.onPrepared
is called when preparation completes. If preparation fails,
maybeThrowPrepareError()
will throw an IOException
.
If preparation succeeds and results in a source timeline change (e.g. the period duration
becoming known), MediaSource.Listener.onSourceInfoRefreshed(Timeline, Object)
will be
called before callback.onPrepared
.
callback
- Callback to receive updates from this period, including being notified when
preparation completes.void maybeThrowPrepareError() throws java.io.IOException
This method should only be called before the period has completed preparation.
java.io.IOException
- The underlying error.TrackGroupArray getTrackGroups()
TrackGroup
s exposed by the period.
This method should only be called after the period has been prepared.
TrackGroup
s.long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, long positionUs)
The call receives track selections
for each renderer, mayRetainStreamFlags
indicating whether the existing SampleStream
can be retained for each selection, and
the existing stream
s themselves. The call will update streams
to reflect the
provided selections, clearing, setting and replacing entries as required. If an existing sample
stream is retained but with the requirement that the consuming renderer be reset, then the
corresponding flag in streamResetFlags
will be set to true. This flag will also be set
if a new sample stream is created.
This method should only be called after the period has been prepared.
selections
- The renderer track selections.mayRetainStreamFlags
- Flags indicating whether the existing sample stream can be retained
for each selection. A true
value indicates that the selection is unchanged, and
that the caller does not require that the sample stream be recreated.streams
- The existing sample streams, which will be updated to reflect the provided
selections.streamResetFlags
- Will be updated to indicate new sample streams, and sample streams that
have been retained but with the requirement that the consuming renderer be reset.positionUs
- The current playback position in microseconds.void discardBuffer(long positionUs)
positionUs
- The position in microseconds.long readDiscontinuity()
After this method has returned a value other than C.TIME_UNSET
, all
SampleStream
s provided by the period are guaranteed to start from a key frame.
C.TIME_UNSET
.long getBufferedPositionUs()
This method should only be called when at least one track is selected.
C.TIME_END_OF_SOURCE
if the track is fully buffered.long seekToUs(long positionUs)
After this method has been called, all SampleStream
s provided by the period are
guaranteed to start from a key frame.
This method should only be called when at least one track is selected.
positionUs
- The seek position in microseconds.long getNextLoadPositionUs()
C.TIME_END_OF_SOURCE
if loading has finished.
This method should only be called after the period has been prepared. It may be called when no tracks are selected.
getNextLoadPositionUs
in interface SequenceableLoader
boolean continueLoading(long positionUs)
This method may be called both during and after the period has been prepared.
A period may call SequenceableLoader.Callback.onContinueLoadingRequested(SequenceableLoader)
on the
MediaPeriod.Callback
passed to prepare(Callback)
to request that this method be called
when the period is permitted to continue loading data. A period may do this both during and
after preparation.
continueLoading
in interface SequenceableLoader
positionUs
- The current playback position.getNextLoadPositionUs()
will return
a different value than prior to the call. False otherwise.