M - The type of the manifest object.K - The type of the representation key object.public abstract class SegmentDownloader<M,K> extends java.lang.Object implements Downloader
All of the methods are blocking. Also they are not thread safe, except getTotalSegments(), getDownloadedSegments() and getDownloadedBytes().
| Modifier and Type | Class and Description |
|---|---|
protected static class |
SegmentDownloader.Segment
Smallest unit of content to be downloaded.
|
Downloader.ProgressListener| Constructor and Description |
|---|
SegmentDownloader(android.net.Uri manifestUri,
DownloaderConstructorHelper constructorHelper) |
| Modifier and Type | Method and Description |
|---|---|
void |
download(Downloader.ProgressListener listener)
Downloads the content for the selected representations in sync or resumes a previously stopped
download.
|
abstract K[] |
getAllRepresentationKeys()
Returns keys for all representations.
|
long |
getDownloadedBytes()
Returns the total number of downloaded bytes in the representations which are selected, or
C.LENGTH_UNSET if it hasn't been calculated yet. |
int |
getDownloadedSegments()
Returns the total number of downloaded segments in the representations which are selected, or
C.LENGTH_UNSET if it hasn't been calculated yet. |
float |
getDownloadPercentage()
Returns the download percentage, or
Float.NaN if it can't be calculated yet. |
M |
getManifest()
Returns the manifest.
|
protected abstract M |
getManifest(DataSource dataSource,
android.net.Uri uri)
Loads and parses the manifest.
|
protected abstract java.util.List<SegmentDownloader.Segment> |
getSegments(DataSource dataSource,
M manifest,
K[] keys,
boolean allowIncompleteIndex)
Returns a list of
SegmentDownloader.Segments for given keys. |
int |
getTotalSegments()
Returns the total number of segments in the representations which are selected, or
C.LENGTH_UNSET if it hasn't been calculated yet. |
void |
init()
Initializes the total segments, downloaded segments and downloaded bytes counters for the
selected representations.
|
void |
remove()
Removes all of the downloaded data of the media.
|
void |
selectRepresentations(K[] keys)
Selects multiple representations pointed to by the keys for downloading, checking status.
|
public SegmentDownloader(android.net.Uri manifestUri,
DownloaderConstructorHelper constructorHelper)
manifestUri - The Uri of the manifest to be downloaded.constructorHelper - a DownloaderConstructorHelper instance.public final M getManifest() throws java.io.IOException
java.io.IOException - If an error occurs reading data.public final void selectRepresentations(K[] keys)
public abstract K[] getAllRepresentationKeys() throws java.io.IOException
java.io.IOExceptionselectRepresentations(Object[])public final void init()
throws java.lang.InterruptedException,
java.io.IOException
init in interface Downloaderjava.io.IOException - Thrown when there is an io error while reading from cache.DownloadException - Thrown if the media cannot be downloaded.java.lang.InterruptedException - If the thread has been interrupted.getTotalSegments(),
getDownloadedSegments(),
getDownloadedBytes()public final void download(@Nullable
Downloader.ProgressListener listener)
throws java.io.IOException,
java.lang.InterruptedException
download in interface Downloaderlistener - If not null, called during download.java.io.IOException - Thrown when there is an io error while downloading.DownloadException - Thrown if the media cannot be downloaded.java.lang.InterruptedException - If the thread has been interrupted.public final int getTotalSegments()
C.LENGTH_UNSET if it hasn't been calculated yet.init()public final int getDownloadedSegments()
C.LENGTH_UNSET if it hasn't been calculated yet.init()public final long getDownloadedBytes()
C.LENGTH_UNSET if it hasn't been calculated yet.getDownloadedBytes in interface Downloaderinit()public float getDownloadPercentage()
DownloaderFloat.NaN if it can't be calculated yet. This
value can be an estimation.getDownloadPercentage in interface DownloaderDownloader.init()public final void remove()
throws java.lang.InterruptedException
Downloaderremove in interface Downloaderjava.lang.InterruptedException - Thrown if the thread was interrupted.protected abstract M getManifest(DataSource dataSource, android.net.Uri uri) throws java.io.IOException
dataSource - The DataSource through which to load.uri - The manifest uri.java.io.IOException - If an error occurs reading data.protected abstract java.util.List<SegmentDownloader.Segment> getSegments(DataSource dataSource, M manifest, K[] keys, boolean allowIncompleteIndex) throws java.lang.InterruptedException, java.io.IOException
SegmentDownloader.Segments for given keys.dataSource - The DataSource through which to load any required data.manifest - The manifest containing the segments.keys - The selected representation keys.allowIncompleteIndex - Whether to continue in the case that a load error prevents all
segments from being listed. If true then a partial segment list will be returned. If false
an IOException will be thrown.SegmentDownloader.Segments for given keys.java.lang.InterruptedException - Thrown if the thread was interrupted.java.io.IOException - Thrown if allowPartialIndex is false and a load error occurs, or if
the media is not in a form that allows for its segments to be listed.