Class MediaDownloadable
- Direct Known Subclasses:
DashDownloadable
,Mp4Downloadable
Video
) to be downloaded
and responsible to manage the download of its components such as video, audio and text.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
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
Interface definition for a callback to be invoked when the video tracks have been read and are available.static interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The key for the Bundle which returns the available audio language roles as ArrayList, matching the size and indexes of AUDIO_LANGUAGES
.static final String
The key for the Bundle which returns the available audio languages as ArrayListstatic final String
The key for the Bundle which returns the available captions as ArrayListprotected final android.os.Bundle
protected final android.content.Context
static final String
The name of that will be used for saving DASH manifest.protected final MediaDownloadable.DownloadEventListener
protected final DownloadManager
protected long
protected final RequestConfig
protected final Video
static final String
The key for the Bundle which returns the available video renditions as ArrayList -
Constructor Summary
ConstructorDescriptionMediaDownloadable
(android.content.Context context, Video video, MediaDownloadable.DownloadEventListener downloadEventListener, RequestConfig requestConfig) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Cancels download of the media if it has not been completed yet.static MediaDownloadable
create
(android.content.Context context, Video video, MediaDownloadable.DownloadEventListener downloadEventListener, RequestConfig requestConfig) Creates the bestMediaDownloadable
for the given video based on the supported delivery types.static MediaDownloadable
create
(android.content.Context context, String videoUrl, MediaDownloadable.DownloadEventListener downloadEventListener, RequestConfig requestConfig) Creates the bestMediaDownloadable
for the given video url 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 theDownloadManager
.boolean
Deletes the offline copy of the media.protected void
enqueueDownloadRequest
(DownloadManager.Request... requests) Enqueues a list of download requests to the download manager.void
Returns the estimated total size of the media, which includes all assets such video, audio and subtitles.android.os.Bundle
Gets the directory the will hold all the assets related to this media.Checks the overall download status by inspecting the status of each request in the entire download set.long
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 HashMap<String,
Serializable> protected String
getMediaUrl
(DeliveryType type) Get the media URL from the video's source collection.protected void
Called when the media download has been removed before the download has completed.protected void
Called when the media download has completed successfully.protected void
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
Called when the media download progress has changed.protected void
This method will be called when theMediaDownloadable
starts to process the download request.protected void
This method will be called when theMediaDownloadable
starts to download the media.int
Attempts to pause download of this media.static void
registerDownloadable
(DeliveryType deliveryType, Class<? extends MediaDownloadable> downloadableClass) Registers the downloadable class that must be used to handled download of the specified media delivery type.boolean
Requests the media to be downloaded asynchronously.int
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.
-
Field Details
-
DEFAULT_MPD_NAME
The name of that will be used for saving DASH manifest.- See Also:
-
VIDEO_RENDITIONS
The key for the Bundle which returns the available video renditions as ArrayList- See Also:
-
AUDIO_LANGUAGES
The key for the Bundle which returns the available audio languages as ArrayList- See Also:
-
AUDIO_LANGUAGE_ROLES
The key for the Bundle which returns the available audio language roles as ArrayList, matching the size and indexes of AUDIO_LANGUAGES
.- See Also:
-
CAPTIONS
The key for the Bundle which returns the available captions as ArrayList- See Also:
-
configurationBundle
protected final android.os.Bundle configurationBundle -
context
protected final android.content.Context context -
downloadManager
-
video
-
downloadEventListener
-
requestConfig
-
estimatedSize
protected long estimatedSize
-
-
Constructor Details
-
MediaDownloadable
public MediaDownloadable(@NonNull android.content.Context context, @NonNull Video video, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig)
-
-
Method Details
-
getMediaFormatTracksAvailable
public abstract void getMediaFormatTracksAvailable(@NonNull MediaDownloadable.MediaFormatListener mediaFormatListener) An asynchronous call to retrieve the MediaFormat tracks available for the current video. The result will be given through theMediaDownloadable.MediaFormatListener
listener.Note: Only the video type
DeliveryType.DASH
is currently supported.- Parameters:
mediaFormatListener
- the media format listener
-
registerDownloadable
public static void registerDownloadable(@NonNull DeliveryType deliveryType, @NonNull Class<? extends MediaDownloadable> downloadableClass) Registers the downloadable class that must be used to handled download of the specified media delivery type.- Parameters:
deliveryType
- the deliverty typedownloadableClass
- the media downloadable class.
-
create
@Nullable public static MediaDownloadable create(@NonNull android.content.Context context, @NonNull Video video, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig) Creates the bestMediaDownloadable
for the given video based on the supported delivery types.- Parameters:
context
- the context of the application.video
- the video to be downloaded.requestConfig
- the request configuration object passed to theDownloadManager
.- Returns:
- null if the video is not flagged for offline playback or if no suitable delivery
type was found in the video, otherwise reference to a
MediaDownloadable
that can be used download/manage the video.
-
create
@Nullable public static MediaDownloadable create(@NonNull android.content.Context context, @NonNull String videoUrl, @Nullable MediaDownloadable.DownloadEventListener downloadEventListener, @Nullable RequestConfig requestConfig) Creates the bestMediaDownloadable
for the given video url on the supported delivery types.- Parameters:
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.- Returns:
- null if no suitable delivery type was found in the video, otherwise reference to a
MediaDownloadable
that can be used download/managed the video.
-
setVideoBitrate
public void setVideoBitrate(int videoBitrate) Sets the video bitrate cap which will be used to determine what rendition will be downloaded. If there's no rendition lower than the video bitrate provided, the next higher will be picked.- Parameters:
videoBitrate
- the video bitrate
-
getDownloadDirectory
Gets the directory the will hold all the assets related to this media.- Returns:
- the directory the will hold all the assets related to this media.
-
getEstimatedSize
public long getEstimatedSize()Returns the estimated total size of the media, which includes all assets such video, audio and subtitles. Please note the method should be called after callingrequestDownload()
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.
- Returns:
- the approximate size of the media
-
estimatedSize
Returns the estimated total size of the media, which includes all assets such video, audio and subtitles.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.- Parameters:
callback
- the approximate size of the media.
-
getConfigurationBundle
public android.os.Bundle getConfigurationBundle() -
setConfigurationBundle
public void setConfigurationBundle(android.os.Bundle bundle) -
enqueueDownloadRequest
Enqueues a list of download requests to the download manager. The actual status of the download request will be published to the
downloadEventListener
. Please usegetDownloadStatus()
to query the download status.Please note that this method must only be called once to enqueue all download requests.
- Parameters:
requests
- an array of download requests- Throws:
IllegalStateException
- If the video has been already queued for download.
-
onMediaDownloadRequested
protected void onMediaDownloadRequested()This method will be called when theMediaDownloadable
starts to process the download request. -
getMediaProperties
-
onMediaDownloadStarted
protected void onMediaDownloadStarted()This method will be called when theMediaDownloadable
starts to download the media. -
onMediaDownloadPaused
Called when the media download has been paused. -
onMediaDownloadProgress
Called when the media download progress has changed. -
onMediaDownloadComplete
Called when the media download has completed successfully. -
onMediaDownloadFailed
Called when the media download has failed. -
onMediaDownloadCancelled
protected void onMediaDownloadCancelled()Called when the media download has been removed before the download has completed. -
onMediaDownloadDeleted
protected void onMediaDownloadDeleted()Called when the media download has been removed after the download has completed. -
requestDownload
public boolean requestDownload()Requests the media to be downloaded asynchronously.- Returns:
- true if the request was successfully placed in the download queue, otherwise false.
Please note that a true value does not mean that media has been downloaded successfully.
The actual status of the download request will be published to the
downloadEventListener
. Please usegetDownloadStatus()
to query the download status. - Throws:
IllegalStateException
- If the video has been already queued for download.
-
pauseDownload
public int pauseDownload()Attempts to pause download of this media.- Returns:
- the status of the media download.
-
resumeDownload
public int resumeDownload()Attempts to resume download of this media.- Returns:
- the status of the media download.
-
cancelDownload
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.- Returns:
- true if the media was found in the download queue and cancelled, otherwise false.
-
deleteDownload
public boolean deleteDownload()Deletes the offline copy of the media. If the media has not been fully downloaded yet, then it will be removed from the download queue and any partially download assets belonging to the media will be deleted.- Returns:
- true if the media was removed from the download queue and the storage, otherwise false.
-
getDownloadStatus
Checks the overall download status by inspecting the status of each request in the entire download set. Please note that this is a blocking call. Checking the status of large media with multiple assets may take time. -
createDownloadRequest
@NonNull protected DownloadManager.Request createDownloadRequest(@NonNull android.net.Uri requestUri, @NonNull android.net.Uri destinationUri) Create a download request which can be enqueued with theDownloadManager
.- Parameters:
requestUri
- the request uridestinationUri
- the destination uri- Returns:
- the download request
- See Also:
-
getMediaUrl
Get the media URL from the video's source collection.- Parameters:
type
- The delivery type- Returns:
- The media URL or null if no sources exist for the given type.
-