OTVPersistenceManager

final public class OTVPersistenceManager : NSObject

OTVPersistenceManager is a singleton that manages all download related functionality. It utilises OTVDownloadingAssetManager for outstanding downloads and OTVAssetsManager for completed downloads.

  • Persistence Manager singleton instance.

    Declaration

    Swift

    @objc
    public static let shared: OTVPersistenceManager
  • Start a media stream dowloading.

    Note

    You MUST NOT share the same license delegate instance for multiple downloading.

    Declaration

    Swift

    @objc(startDownloadWithUrlAsset:title:licenseDelegate:artwork:options:)
    public func startDownload(urlAsset: AVURLAsset, title: String, licenseDelegate: OTVLicenseDelegate?, artwork: Data?, options: [String : Any]? = nil) -> OTVPersistenceAsset?

    Parameters

    urlAsset

    Asset needs to be downloaded

    title

    Stream’s title

    licenseDelegate

    Delegate to fetch the license

    artwork

    artwork Data

    options

    download options

    Return Value

    an asset created for this download.

  • Start Preparing a media stream ready for dowloading.

    Note

    • To begin the download you must wait for the prepared download state on the OTVPersistenceAsset returned here.
    • Once the OTVPersistenceAsset has entered prepared state:
    • You can check the mediaInfo values on the OTVPersistenceAsset
    • You can query the OTVPersistenceAsset.mediaInfo.availableStreamInfo to see all the information needed to start downloading the asset.
    • You can query the OTVPersistenceAsset.mediaInfo.availableDrmInfo to get the drm information of the asset.
    • You SHOULD retain the object returned from preparedDownload, and pass the object to call startDownload: persistenceAsset… when state is changed to Prepared

    Declaration

    Swift

    @objc(prepareDownloadWithUrl:title:)
    public func prepareDownload(url: URL, title: String) -> OTVPersistenceAsset

    Parameters

    url

    Url of asset needs to be downloaded

    title

    Stream’s title

    Return Value

    an asset created for this download.

  • Start a media stream dowloading for a OTVPersistenceAsset

    Note

    • You MUST call prepareDownload and wait for state Prepared on the OTVPersistenceAsset before calling this function
      • If the stream is FPS encrypted, you MUST call setupFPS: on the prepared OTVPersistenceAsset before calling this function, and pass an OTVLicenseDelegate instance;
      • If the stream is PRM encrypted, you MUST call setupPRM: on the prepared OTVPersistenceAsset before call this function, and pass an OTVPRMAVURLAsset object;
      • If the stream is clear one, you SHOULD NOT call setupFPS: or setupPRM: on the prepared OTVPersistenceAsset.
      • You can set a number of values on the OTVPersistenceAsset to choose what resolution and bitrate you want to download
      • You can do this by setting OTVPersistenceAsset.mediaInfo.selectedStreamInfo from selection one of the OTVPersistenceAsset.mediaInfo.availableStreamInfo
      • If no value is set for OTVPersistenceAsset.mediaInfo.selectedStreamInfo we will check the options value passed into this function.
      • If neither of these values are set then we will use the highest possible value you are able to download.

    Declaration

    Swift

    @objc(startDownloadWithAsset:artwork:options:avMediaSelectionOptions:)
    public func startDownload(asset: OTVPersistenceAsset, artwork: Data?, options: [String : Any]? = nil, avMediaSelectionOptions: [AVMediaSelection]? = nil) -> Bool

    Parameters

    asset

    an object of OTVPersistenceAsset in prepared state

    artwork

    artwork Data

    options

    download options

    avMediaSelectionOptions

    the media selection to download, if it is not set, the default selection will be download

    Return Value

    True if download start successful, False if there is some error, e.g. the asset is not in prepared state.

  • Start a media stream dowloading for a OTVPersistenceAsset

    Note

    • You MUST call prepareDownload and wait for state Prepared on the OTVPersistenceAsset before calling this function
      • If the stream is FPS encrypted, you MUST call setupFPS: on the prepared OTVPersistenceAsset before calling this function, and pass an OTVLicenseDelegate instance;
      • If the stream is PRM encrypted, you MUST call setupPRM: on the prepared OTVPersistenceAsset before call this function, and pass an OTVPRMAVURLAsset object;
      • If the stream is clear one, you SHOULD NOT call setupFPS: or setupPRM: on the prepared OTVPersistenceAsset.
      • You can set a number of values on the OTVPersistenceAsset to choose what resolution and bitrate you want to download
      • You can do this by setting OTVPersistenceAsset.mediaInfo.selectedStreamInfo from selection one of the OTVPersistenceAsset.mediaInfo.availableStreamInfo
      • If no value is set for OTVPersistenceAsset.mediaInfo.selectedStreamInfo we will check the options value passed into this function.
      • If neither of these values are set then we will use the highest possible value you are able to download.

    Declaration

    Swift

    @objc(startDownloadWithAsset:artwork:options:)
    public func startDownload(asset: OTVPersistenceAsset, artwork: Data?, options: [String : Any]? = nil) -> Bool

    Parameters

    asset

    an object of OTVPersistenceAsset in prepared state

    artwork

    artwork Data

    options

    download options

    Return Value

    True if download start successful, False if there is some error, e.g. the asset is not in prepared state.

  • Return downloading and downloaded assets.

    Declaration

    Swift

    @objc
    public func getDownloads() -> [OTVPersistenceAsset]?
  • Pause the downloading of assigned asset.

    Declaration

    Swift

    @objc
    public func pauseDownload(asset: OTVPersistenceAsset) -> Bool

    Parameters

    asset

    the asset to be paused.

  • Resume the paused downloading asset.

    Declaration

    Swift

    @objc
    public func resumeDownload(asset: OTVPersistenceAsset) -> Bool

    Parameters

    asset

    the asset to be resumed.

  • Cancel or remove the asset.

    Declaration

    Swift

    @objc
    public func deleteDownload(asset: OTVPersistenceAsset) -> Bool

    Parameters

    asset

    the asset to be cancelled or removed.

  • Extends OTVPersistenceManager to define a number of values to use as keys in dictionary options.

    See more

    Declaration

    Swift

    public struct Keys
  • Declaration

    Swift

    @objc
    public func totalDiskSpaceInBytes() -> Int64
  • Declaration

    Swift

    @objc
    public func freeDiskSpaceInBytes() -> Int64
  • Declaration

    Swift

    @objc
    public func usedDiskSpaceInBytes() -> Int64