public final class HlsPlaylistTracker extends java.lang.Object implements com.google.android.exoplayer2.upstream.Loader.Callback<com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist>>
Modifier and Type | Class 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.
|
Constructor and Description |
---|
HlsPlaylistTracker(android.net.Uri initialPlaylistUri,
HlsDataSourceFactory dataSourceFactory,
com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher eventDispatcher,
int minRetryCount,
HlsPlaylistTracker.PrimaryPlaylistListener primaryPlaylistListener) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(HlsPlaylistTracker.PlaylistEventListener listener)
Registers a listener to receive events from the playlist tracker.
|
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 this is live content.
|
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 |
onLoadCanceled(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable,
long elapsedRealtimeMs,
long loadDurationMs,
boolean released) |
void |
onLoadCompleted(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable,
long elapsedRealtimeMs,
long loadDurationMs) |
int |
onLoadError(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable,
long elapsedRealtimeMs,
long loadDurationMs,
java.io.IOException error) |
void |
refreshPlaylist(HlsMasterPlaylist.HlsUrl url)
Triggers a playlist refresh and whitelists it.
|
void |
release()
Releases the playlist tracker.
|
void |
removeListener(HlsPlaylistTracker.PlaylistEventListener listener)
Unregisters a listener.
|
void |
start()
Starts tracking all the playlists related to the provided Uri.
|
public HlsPlaylistTracker(android.net.Uri initialPlaylistUri, HlsDataSourceFactory dataSourceFactory, com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher eventDispatcher, int minRetryCount, HlsPlaylistTracker.PrimaryPlaylistListener primaryPlaylistListener)
initialPlaylistUri
- Uri for the initial playlist of the stream. Can refer a media
playlist or a master playlist.dataSourceFactory
- A factory for DataSource
instances.eventDispatcher
- A dispatcher to notify of events.minRetryCount
- The minimum number of times the load must be retried before blacklisting a
playlist.primaryPlaylistListener
- A callback for the primary playlist change events.public void addListener(HlsPlaylistTracker.PlaylistEventListener listener)
listener
- The listener.public void removeListener(HlsPlaylistTracker.PlaylistEventListener listener)
listener
- The listener to unregister.public void start()
public HlsMasterPlaylist getMasterPlaylist()
public 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.public 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.public void release()
public void maybeThrowPrimaryPlaylistRefreshError() throws java.io.IOException
java.io.IOException
- The underlying error.public 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.public void refreshPlaylist(HlsMasterPlaylist.HlsUrl url)
url
- The HlsMasterPlaylist.HlsUrl
of the playlist to be refreshed.public boolean isLive()
public void onLoadCompleted(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable, long elapsedRealtimeMs, long loadDurationMs)
onLoadCompleted
in interface com.google.android.exoplayer2.upstream.Loader.Callback<com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist>>
public void onLoadCanceled(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released)
onLoadCanceled
in interface com.google.android.exoplayer2.upstream.Loader.Callback<com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist>>
public int onLoadError(com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist> loadable, long elapsedRealtimeMs, long loadDurationMs, java.io.IOException error)
onLoadError
in interface com.google.android.exoplayer2.upstream.Loader.Callback<com.google.android.exoplayer2.upstream.ParsingLoadable<HlsPlaylist>>