Package com.castlabs.sdk.downloader

## Class Download

- java.lang.Object
- - com.castlabs.sdk.downloader.Download

- All Implemented Interfaces:
    `Serializable`

      public class Download
      extends Object
      implements Serializable

  The download model class
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `Download.State` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `STATE_DONE` | The download is completed
    `static int` | `STATE_ERROR` | At least one chunk download failed and the download is in error state
    `static int` | `STATE_IDLE` | The download is paused
    `static int` | `STATE_LOADING` | The download is currently downloading
    `static int` | `STATE_QUEUED` | The download is queued for loading

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Download​(String id, String remoteUrl, File localBaseFolder, boolean mergeVideoTracks)` | Create Download with specified Id, manifest URL and base folder for storage.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `equals​(Object o)` |
    `AudioTrack[]` | `getAudioTracks()` | Get all available (remote) audio tracks or null if no audio tracks are available.
    `long` | `getDownloadedSize()` | Returns the size in bytes of the currently download data on disk.
    `DrmConfiguration` | `getDrmConfiguration()` | Returns the content DRM configuration.
    `long` | `getEstimatedSize()` | Returns the total size of all selected tracks of this download.
    `Bundle` | `getHeaderParams()` | Returns a Bundle with the extra header key:values that will be added to the requests.
    `String` | `getId()` |
    `File` | `getLocalBaseFolder()` | The local folder that contains the files for this download.
    `String` | `getLocalManifestUrl()` | Returns the path to the local Manifest.
    `boolean` | `getMergeVideoTracks()` | The flag specifying the video tracks should be merged or not
    `Bundle` | `getQueryParams()` | Returns a Bundle with the extra query params that will be added to the requests.
    `String` | `getRemoteUrl()` |
    `int[]` | `getSelectedAudioTracks()` | Get the array of selected audio tracks by index
    `int[]` | `getSelectedSubtitleTracks()` |
    `int` | `getSelectedVideoTrackQuality()` | Get the index of the selected video track
    `long` | `getSize​(int mediaType, int trackIndex)` | Returns the size of the chunk with the given media type, i.e `SdkConsts.VIDEO`, `SdkConsts.AUDIO`, `SdkConsts.TEXT`, or `SdkConsts.OTHER`, and its track index.
    `int` | `getState()` | Get the current state of this download
    `com.castlabs.sdk.downloader.TrackDownload[]` | `getSubtitleTrackDownloads()` |
    `SubtitleTrack[]` | `getSubtitleTracks()` | Get all available (remote) subtitle tracks or null if no subtitle tracks are available.
    `VideoTrackQuality[]` | `getVideoTrackQualities()` | All available (remote) video representations.
    `int` | `hashCode()` |
    `void` | `setHeaderParams​(Bundle headers)` | Sets the headers to add to the download requests.
    `void` | `setQueryParams​(Bundle queryParams)` | Sets the query params to add to the download requests.
    `void` | `setSelectedAudioTracks​(int[] selectedAudioTracks)` | Set the array of selected audio tracks
    `void` | `setSelectedSubtitleTracks​(int[] selectedSubtitleTracks)` | Set the selected subtitle tracks by index
    `void` | `setSelectedVideoTrackQuality​(int selectedVideoTrackQuality)` | Set the selected video track quality using its index in the list of available representations.
    `String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### STATE_QUEUED

          public static final int STATE_QUEUED

      The download is queued for loading
      See Also:
        Constant Field Values

    - #### STATE_LOADING

          public static final int STATE_LOADING

      The download is currently downloading
      See Also:
        Constant Field Values

    - #### STATE_ERROR

          public static final int STATE_ERROR

      At least one chunk download failed and the download is in error state
      See Also:
        Constant Field Values

    - #### STATE_DONE

          public static final int STATE_DONE

      The download is completed
      See Also:
        Constant Field Values

    - #### STATE_IDLE

          public static final int STATE_IDLE

      The download is paused
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Download

          public Download​(@NonNull
                          String id,
                          @NonNull
                          String remoteUrl,
                          @NonNull
                          File localBaseFolder,
                          boolean mergeVideoTracks)

      Create Download with specified Id, manifest URL and base folder for storage.
      Parameters:
        `id` - Current download Id
        `remoteUrl` - Manifest remote URL
        `localBaseFolder` - Base folder for storing current download

  - ### Method Detail

    - #### getId

          @NonNull
          public String getId()

      Returns:
        The unique ID that identifies this download

    - #### getRemoteUrl

          @NonNull
          public String getRemoteUrl()

      Returns:
        The remote URL that us the primary source for this download

    - #### getLocalBaseFolder

          @NonNull
          public File getLocalBaseFolder()

      The local folder that contains the files for this download. Each download usually has a unique folder that contains all files related to this download.
      Returns:
        The local folder that contains the files for this download

    - #### getMergeVideoTracks

          public boolean getMergeVideoTracks()

      The flag specifying the video tracks should be merged or not
      Returns:
        The merge video tracks flag

    - #### getVideoTrackQualities

          @Nullable
          public VideoTrackQuality[] getVideoTrackQualities()

      All available (remote) video representations. This represents all video qualities that are available on the remote, not only the locally available representations.
      Returns:
        All available video representations

    - #### getDownloadedSize

          public long getDownloadedSize()

      Returns the size in bytes of the currently download data on disk.
      Returns:
        Currently downloaded data

    - #### getAudioTracks

          @Nullable
          public AudioTrack[] getAudioTracks()

      Get all available (remote) audio tracks or null if no audio tracks are available. This represents all audio tracks that are available on the remote, not only the locally available tracks.
      Returns:
        The available (remote) audio tracks

    - #### getSubtitleTracks

          @Nullable
          public SubtitleTrack[] getSubtitleTracks()

      Get all available (remote) subtitle tracks or null if no subtitle tracks are available. This represents all subtitle tracks that are available on the remote, not only the locally available tracks.
      Returns:
        The available (remote) subtitle tracks

    - #### getSelectedVideoTrackQuality

          public int getSelectedVideoTrackQuality()

      Get the index of the selected video track
      Returns:
        The index of the selected video track.

    - #### setSelectedVideoTrackQuality

          public void setSelectedVideoTrackQuality​(int selectedVideoTrackQuality)

      Set the selected video track quality using its index in the list of available representations.
      Parameters:
        `selectedVideoTrackQuality` - The video track quality index

    - #### getSelectedAudioTracks

          @Nullable
          public int[] getSelectedAudioTracks()

      Get the array of selected audio tracks by index
      Returns:
        The array of selected audio tracks by index

    - #### setSelectedAudioTracks

          public void setSelectedAudioTracks​(@Nullable
                                             int[] selectedAudioTracks)

      Set the array of selected audio tracks
      Parameters:
        `selectedAudioTracks` - The selected audio tracks

    - #### getSelectedSubtitleTracks

          @Nullable
          public int[] getSelectedSubtitleTracks()

      Returns:
        The array of selected subtitle tracks by index

    - #### setSelectedSubtitleTracks

          public void setSelectedSubtitleTracks​(@Nullable
                                                int[] selectedSubtitleTracks)

      Set the selected subtitle tracks by index
      Parameters:
        `selectedSubtitleTracks` - The selected subtitle tracks by index

    - #### getLocalManifestUrl

          @Nullable
          public String getLocalManifestUrl()

      Returns the path to the local Manifest. Once the download is completed, this path can be used to start playback of the local content.
      Returns:
        The path to the local manifest

    - #### getDrmConfiguration

          @Nullable
          public DrmConfiguration getDrmConfiguration()

      Returns the content DRM configuration.
      Returns:
        Content DRM configuration

    - #### getState

          public int getState()

      Get the current state of this download
      Returns:
        The current state of this download

    - #### getEstimatedSize

          public long getEstimatedSize()

      Returns the total size of all selected tracks of this download.

      Note that the manifest size only will be returned when no tracks are selected.

      Please also note that the number of bytes returned here is an estimate of the total size of the download. Depending on the download source, i.e. file, DASH, or SmoothStreaming, information from the source is used to create this estimate. For example, for SmoothStreaming content, a track size is estimated based on the bitrate and the duration of the track. The same is true for segmented DASH. If a DASH source is based on single files, we try to use the information from the manifest that is used to generate the range requests to estimate the size. The latter is more accurate than simply using the specified bitrate, but it is still an estimate.

      Returns:
        The estimated size in bytes of this download

    - #### getSize

          public long getSize​(int mediaType,
                              int trackIndex)

      Returns the size of the chunk with the given media type, i.e `SdkConsts.VIDEO`, `SdkConsts.AUDIO`, `SdkConsts.TEXT`, or `SdkConsts.OTHER`, and its track index.
      Parameters:
        `mediaType` - The media type
        `trackIndex` - The track index
      Returns:
        The size in bytes or 0

    - #### equals

          public boolean equals​(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          @NonNull
          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getSubtitleTrackDownloads

          public com.castlabs.sdk.downloader.TrackDownload[] getSubtitleTrackDownloads()

    - #### getHeaderParams

          @NonNull
          public Bundle getHeaderParams()

      Returns a Bundle with the extra header key:values that will be added to the requests.

      This Bundle will contain the headers informed with the `SdkConsts.INTENT_HEADER_PARAMS_BUNDLE` key in the Bundle passed to `DownloadServiceBinder.prepareDownload(Context, Bundle, Downloader.ModelReadyCallback)`.

      Returns:
        a Bundle with the extra header key:values that will be added to the requests.

    - #### setHeaderParams

          public void setHeaderParams​(@Nullable
                                      Bundle headers)

      Sets the headers to add to the download requests.

      If null, all already existing headers will be cleared.

      Parameters:
        `headers` - a Bundle containing headers to add to the download requests

    - #### getQueryParams

          @NonNull
          public Bundle getQueryParams()

      Returns a Bundle with the extra query params that will be added to the requests.

      This Bundle will contain the query params informed with the `SdkConsts.INTENT_QUERY_PARAMS_BUNDLE` key in the Bundle passed to `DownloadServiceBinder.prepareDownload(Context, Bundle, Downloader.ModelReadyCallback)`.

      Returns:
        a Bundle with the extra query params that will be added to the requests.

    - #### setQueryParams

          public void setQueryParams​(@Nullable
                                     Bundle queryParams)

      Sets the query params to add to the download requests.

      If null, all already existing query params will be cleared.

      Parameters:
        `queryParams` - a Bundle containing query params to add to the download requests