public abstract class MediaDownloadable
extends java.lang.Object
Video
) to be downloaded
and responsible to manage the download of its components such as video, audio and text.Modifier and Type | Class and Description |
---|---|
static interface |
MediaDownloadable.DownloadEventListener
Interface definition for a callback to be invoked when a media download is either completed,
cancelled or failed because an error has occurred.
|
static interface |
MediaDownloadable.MediaFormatListener
Interface definition for a callback to be invoked when the video tracks have been read
and are available.
|
static interface |
MediaDownloadable.OnVideoSizeCallback |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AUDIO_LANGUAGE_ROLES
The key for the Bundle which returns the available audio language roles
as ArrayList
AUDIO_LANGUAGES . |
static java.lang.String |
AUDIO_LANGUAGES
The key for the Bundle which returns the available audio languages
as ArrayList
|
static java.lang.String |
CAPTIONS
The key for the Bundle which returns the available captions
as ArrayList
|
protected android.os.Bundle |
configurationBundle |
protected android.content.Context |
context |
static java.lang.String |
DEFAULT_MPD_NAME
The name of that will be used for saving DASH manifest.
|
protected MediaDownloadable.DownloadEventListener |
downloadEventListener |
protected DownloadManager |
downloadManager |
protected long |
estimatedSize |
protected RequestConfig |
requestConfig |
protected Video |
video |
static java.lang.String |
VIDEO_RENDITIONS
The key for the Bundle which returns the available video renditions
as ArrayList
|
Constructor and Description |
---|
MediaDownloadable(android.content.Context context,
Video video,
MediaDownloadable.DownloadEventListener downloadEventListener,
RequestConfig requestConfig) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancelDownload()
Cancels download of the media if it has not been completed yet.
|
static MediaDownloadable |
create(android.content.Context context,
java.lang.String videoUrl,
MediaDownloadable.DownloadEventListener downloadEventListener,
RequestConfig requestConfig)
Creates the best
MediaDownloadable for the given video url on the supported delivery types. |
static MediaDownloadable |
create(android.content.Context context,
Video video,
MediaDownloadable.DownloadEventListener downloadEventListener,
RequestConfig requestConfig)
Creates the best
MediaDownloadable for the given video based on the supported delivery types. |
protected DownloadManager.Request |
createDownloadRequest(android.net.Uri requestUri,
android.net.Uri destinationUri)
Create a download request which can be enqueued with the
DownloadManager . |
boolean |
deleteDownload()
Deletes the offline copy of the media.
|
protected void |
enqueueDownloadRequest(DownloadManager.Request... requests)
Enqueues a list of download requests to the download manager.
|
void |
estimatedSize(MediaDownloadable.OnVideoSizeCallback callback)
Returns the estimated total size of the media, which includes all assets such video, audio
and subtitles.
|
android.os.Bundle |
getConfigurationBundle() |
java.io.File |
getDownloadDirectory()
Gets the directory the will hold all the assets related to this media.
|
DownloadStatus |
getDownloadStatus()
Checks the overall download status by inspecting the status of each request in the entire
download set.
|
long |
getEstimatedSize()
Returns the estimated total size of the media, which includes all assets such video, audio
and subtitles.
|
abstract void |
getMediaFormatTracksAvailable(MediaDownloadable.MediaFormatListener mediaFormatListener)
An asynchronous call to retrieve the MediaFormat tracks available for the current video.
|
protected abstract java.util.HashMap<java.lang.String,java.io.Serializable> |
getMediaProperties() |
protected void |
onMediaDownloadCancelled()
Called when the media download has been removed before the download has completed.
|
protected void |
onMediaDownloadComplete(DownloadStatus status)
Called when the media download has completed successfully.
|
protected void |
onMediaDownloadDeleted()
Called when the media download has been removed after the download has completed.
|
protected void |
onMediaDownloadFailed(DownloadStatus status)
Called when the media download has failed.
|
protected void |
onMediaDownloadPaused(DownloadStatus status)
Called when the media download has been paused.
|
protected void |
onMediaDownloadProgress(DownloadStatus status)
Called when the media download progress has changed.
|
protected void |
onMediaDownloadRequested()
This method will be called when the
MediaDownloadable starts to process the download request. |
protected void |
onMediaDownloadStarted()
This method will be called when the
MediaDownloadable starts to download the media. |
int |
pauseDownload()
Attempts to pause download of this media.
|
static void |
registerDownloadable(DeliveryType deliveryType,
java.lang.Class<? extends MediaDownloadable> downloadableClass)
Registers the downloadable class that must be used to handled download of the specified
media delivery type.
|
boolean |
requestDownload()
Requests the media to be downloaded asynchronously.
|
int |
resumeDownload()
Attempts to resume download of this media.
|
void |
setConfigurationBundle(android.os.Bundle bundle) |
void |
setVideoBitrate(int videoBitrate)
Sets the video bitrate cap which will be used to determine what rendition will be downloaded.
|
public static final java.lang.String DEFAULT_MPD_NAME
public static final java.lang.String VIDEO_RENDITIONS
public static final java.lang.String AUDIO_LANGUAGES
public static final java.lang.String AUDIO_LANGUAGE_ROLES
AUDIO_LANGUAGES
.public static final java.lang.String CAPTIONS
protected final android.os.Bundle configurationBundle
protected final android.content.Context context
protected final DownloadManager downloadManager
protected final Video video
protected final MediaDownloadable.DownloadEventListener downloadEventListener
protected final RequestConfig requestConfig
protected long estimatedSize
public MediaDownloadable(@NonNull android.content.Context context, @NonNull Video video, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig)
public abstract void getMediaFormatTracksAvailable(@NonNull MediaDownloadable.MediaFormatListener mediaFormatListener)
MediaDownloadable.MediaFormatListener
listener.
Note: Only the video type DeliveryType.DASH
is currently supported.
mediaFormatListener
- the media format listenerpublic static void registerDownloadable(@NonNull DeliveryType deliveryType, @NonNull java.lang.Class<? extends MediaDownloadable> downloadableClass)
deliveryType
- the deliverty typedownloadableClass
- the media downloadable class.@Nullable public static MediaDownloadable create(@NonNull android.content.Context context, @NonNull Video video, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig)
MediaDownloadable
for the given video based on the supported delivery types.context
- the context of the application.video
- the video to be downloaded.requestConfig
- the request configuration object passed to the DownloadManager
.MediaDownloadable
that can be
used download/manage the video.@Nullable public static MediaDownloadable create(@NonNull android.content.Context context, @NonNull java.lang.String videoUrl, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig)
MediaDownloadable
for the given video url on the supported delivery types.context
- the context of the application.videoUrl
- the fully qualified URL of the video to be downloaded.requestConfig
- the request configuration object passed to the download manager.MediaDownloadable
that can be used download/managed the video.public void setVideoBitrate(int videoBitrate)
videoBitrate
- the video bitrate@NonNull public java.io.File getDownloadDirectory()
public long getEstimatedSize()
requestDownload()
The actual size of the media that will be used by the host device may vary based on the partition type and format of the storage.
public void estimatedSize(MediaDownloadable.OnVideoSizeCallback callback)
The actual size of the media that will be used by the host device may vary based on the
partition type and format of the storage.
This method requires the Media Manifest to estimate the size, therefore
it might download the manifest and store it to the directory provided in the
RequestConfig()
object in the constructor, if it has not been done already.
callback
- the approximate size of the media.public android.os.Bundle getConfigurationBundle()
public void setConfigurationBundle(android.os.Bundle bundle)
@NonNull protected void enqueueDownloadRequest(@NonNull DownloadManager.Request... requests)
Enqueues a list of download requests to the download manager. The actual status of the
download request will be published to the downloadEventListener
. Please use
getDownloadStatus()
to query the download status.
Please note that this method must only be called once to enqueue all download requests.
requests
- an array of download requestsjava.lang.IllegalStateException
- If the video has been already queued for download.protected void onMediaDownloadRequested()
MediaDownloadable
starts to process the download request.@NonNull protected abstract java.util.HashMap<java.lang.String,java.io.Serializable> getMediaProperties()
protected void onMediaDownloadStarted()
MediaDownloadable
starts to download the media.protected void onMediaDownloadPaused(@NonNull DownloadStatus status)
protected void onMediaDownloadProgress(@NonNull DownloadStatus status)
protected void onMediaDownloadComplete(@NonNull DownloadStatus status)
protected void onMediaDownloadFailed(@NonNull DownloadStatus status)
protected void onMediaDownloadCancelled()
protected void onMediaDownloadDeleted()
public boolean requestDownload()
downloadEventListener
.
Please use getDownloadStatus()
to query the download status.java.lang.IllegalStateException
- If the video has been already queued for download.public int pauseDownload()
public int resumeDownload()
public boolean cancelDownload()
Cancels download of the media if it has not been completed yet. If the media has been
downloaded already, then calling this method will have no effect.
Please call deleteDownload()
method instead to delete the media.
public boolean deleteDownload()
public DownloadStatus getDownloadStatus()
@NonNull protected DownloadManager.Request createDownloadRequest(@NonNull android.net.Uri requestUri, @NonNull android.net.Uri destinationUri)
DownloadManager
.requestUri
- the request uridestinationUri
- the destination urienqueueDownloadRequest(DownloadManager.Request...)