Class MediaDownloadable

java.lang.Object
com.brightcove.player.offline.MediaDownloadable
Direct Known Subclasses:
DashDownloadable, Mp4Downloadable

public abstract class MediaDownloadable extends Object
An abstract class that holds information related to a remote media (Video) to be downloaded and responsible to manage the download of its components such as video, audio and text.
  • Field Details

    • DEFAULT_MPD_NAME

      public static final String DEFAULT_MPD_NAME
      The name of that will be used for saving DASH manifest.
      See Also:
    • VIDEO_RENDITIONS

      public static final String VIDEO_RENDITIONS
      The key for the Bundle which returns the available video renditions as ArrayList
      See Also:
    • AUDIO_LANGUAGES

      public static final String AUDIO_LANGUAGES
      The key for the Bundle which returns the available audio languages as ArrayList
      See Also:
    • AUDIO_LANGUAGE_ROLES

      public static final String 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

      public static final String 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

      protected final DownloadManager downloadManager
    • video

      protected final Video video
    • downloadEventListener

      protected final MediaDownloadable.DownloadEventListener downloadEventListener
    • requestConfig

      protected final RequestConfig requestConfig
    • estimatedSize

      protected long estimatedSize
  • Constructor Details

  • 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 the MediaDownloadable.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 type
      downloadableClass - 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 best MediaDownloadable 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 the DownloadManager.
      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 best MediaDownloadable 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

      @NonNull public File 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 calling 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.

      Returns:
      the approximate size of the media
    • estimatedSize

      public void estimatedSize(MediaDownloadable.OnVideoSizeCallback callback)
      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

      @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.

      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 the MediaDownloadable starts to process the download request.
    • getMediaProperties

      @NonNull protected abstract HashMap<String,Serializable> getMediaProperties()
    • onMediaDownloadStarted

      protected void onMediaDownloadStarted()
      This method will be called when the MediaDownloadable starts to download the media.
    • onMediaDownloadPaused

      protected void onMediaDownloadPaused(@NonNull DownloadStatus status)
      Called when the media download has been paused.
    • onMediaDownloadProgress

      protected void onMediaDownloadProgress(@NonNull DownloadStatus status)
      Called when the media download progress has changed.
    • onMediaDownloadComplete

      protected void onMediaDownloadComplete(@NonNull DownloadStatus status)
      Called when the media download has completed successfully.
    • onMediaDownloadFailed

      protected void onMediaDownloadFailed(@NonNull DownloadStatus status)
      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 use getDownloadStatus() 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

      public DownloadStatus 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 the DownloadManager.
      Parameters:
      requestUri - the request uri
      destinationUri - the destination uri
      Returns:
      the download request
      See Also:
    • getMediaUrl

      @Nullable protected String getMediaUrl(DeliveryType type)
      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.