public interface HlsPlaylistTracker
The playlist tracker is responsible for exposing the seeking window, which is defined by the segments that one of the playlists exposes. This playlist is called primary and needs to be periodically refreshed in the case of live streams. Note that the primary playlist is one of the media playlists while the master playlist is an optional kind of playlist defined by the HLS specification (RFC 8216).
Playlist loads might encounter errors. The tracker may choose to blacklist them to ensure a primary playlist is always available.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
HlsPlaylistTracker.PlaylistEventListener
Called on playlist loading events.
|
static class |
HlsPlaylistTracker.PlaylistResetException
Thrown when the media sequence of a new snapshot indicates the server has reset.
|
static class |
HlsPlaylistTracker.PlaylistStuckException
Thrown when a playlist is considered to be stuck due to a server side error.
|
static interface |
HlsPlaylistTracker.PrimaryPlaylistListener
Listener for primary playlist changes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(HlsPlaylistTracker.PlaylistEventListener listener)
Registers a listener to receive events from the playlist tracker.
|
long |
getInitialStartTimeUs()
Returns the start time of the first loaded primary playlist, or
C.TIME_UNSET if no
media playlist has been loaded. |
HlsMasterPlaylist |
getMasterPlaylist()
Returns the master playlist.
|
HlsMediaPlaylist |
getPlaylistSnapshot(HlsMasterPlaylist.HlsUrl url)
Returns the most recent snapshot available of the playlist referenced by the provided
HlsMasterPlaylist.HlsUrl. |
boolean |
isLive()
Returns whether the tracked playlists describe a live stream.
|
boolean |
isSnapshotValid(HlsMasterPlaylist.HlsUrl url)
Returns whether the snapshot of the playlist referenced by the provided
HlsMasterPlaylist.HlsUrl is
valid, meaning all the segments referenced by the playlist are expected to be available. |
void |
maybeThrowPlaylistRefreshError(HlsMasterPlaylist.HlsUrl url)
If the playlist is having trouble refreshing the playlist referenced by the given
HlsMasterPlaylist.HlsUrl, this method throws the underlying error. |
void |
maybeThrowPrimaryPlaylistRefreshError()
If the tracker is having trouble refreshing the master playlist or the primary playlist, this
method throws the underlying error.
|
void |
refreshPlaylist(HlsMasterPlaylist.HlsUrl url)
Requests a playlist refresh and whitelists it.
|
void |
removeListener(HlsPlaylistTracker.PlaylistEventListener listener)
Unregisters a listener.
|
void |
start(android.net.Uri initialPlaylistUri,
com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher eventDispatcher,
HlsPlaylistTracker.PrimaryPlaylistListener listener)
Starts the playlist tracker.
|
void |
stop()
Stops the playlist tracker and releases any acquired resources.
|
void start(android.net.Uri initialPlaylistUri,
com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher eventDispatcher,
HlsPlaylistTracker.PrimaryPlaylistListener listener)
Must be called from the playback thread. A tracker may be restarted after a stop()
call.
initialPlaylistUri - Uri of the HLS stream. Can point to a media playlist or a master
playlist.eventDispatcher - A dispatcher to notify of events.listener - A callback for the primary playlist change events.void stop()
Must be called once per start(android.net.Uri, com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher, com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker.PrimaryPlaylistListener) call.
void addListener(HlsPlaylistTracker.PlaylistEventListener listener)
listener - The listener.void removeListener(HlsPlaylistTracker.PlaylistEventListener listener)
listener - The listener to unregister.@Nullable HlsMasterPlaylist getMasterPlaylist()
If the uri passed to start(android.net.Uri, com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher, com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker.PrimaryPlaylistListener) points to a media playlist, an HlsMasterPlaylist
with a single variant for said media playlist is returned.
@Nullable HlsMediaPlaylist getPlaylistSnapshot(HlsMasterPlaylist.HlsUrl url)
HlsMasterPlaylist.HlsUrl.url - The HlsMasterPlaylist.HlsUrl corresponding to the requested media playlist.HlsMasterPlaylist.HlsUrl. May
be null if no snapshot has been loaded yet.long getInitialStartTimeUs()
C.TIME_UNSET if no
media playlist has been loaded.boolean isSnapshotValid(HlsMasterPlaylist.HlsUrl url)
HlsMasterPlaylist.HlsUrl is
valid, meaning all the segments referenced by the playlist are expected to be available. If the
playlist is not valid then some of the segments may no longer be available.url - The HlsMasterPlaylist.HlsUrl.HlsMasterPlaylist.HlsUrl is
valid.void maybeThrowPrimaryPlaylistRefreshError()
throws java.io.IOException
java.io.IOException - The underlying error.void maybeThrowPlaylistRefreshError(HlsMasterPlaylist.HlsUrl url) throws java.io.IOException
HlsMasterPlaylist.HlsUrl, this method throws the underlying error.url - The HlsMasterPlaylist.HlsUrl.java.io.IOException - The underyling error.void refreshPlaylist(HlsMasterPlaylist.HlsUrl url)
The playlist tracker may choose the delay the playlist refresh. The request is discarded if a refresh was already pending.
url - The HlsMasterPlaylist.HlsUrl of the playlist to be refreshed.boolean isLive()