Skip to main content

Offline Playback

SDK and services support offline playback with or without DRM on iOS platforms.

Contract of Offline Manager

The LuraOfflineManagerProtocol defines a set of methods for managing offline video content using the Lura Player SDK.

public protocol LuraOfflineManagerProtocol {

// - Listener
func addListener(listener : LuraOfflineEventListener?) -> String
func removeListener(listenerId : String?)
// - Download Control
func download(config : LuraPlayerConfiguration)
func pauseAll()
func resumeAll()
func pause(config : LuraPlayerConfiguration)
func resume(config : LuraPlayerConfiguration)
func remove(config : LuraPlayerConfiguration)
func removeAll()
// - Video Content Management
func getVideo(config : LuraPlayerConfiguration) -> LuraOfflineVideo?
func getVideos() -> [LuraOfflineVideo]?
// - License Management
func updateLicense(config: LuraPlayerConfiguration)
// - Download Requirements
func setRequirements(requirements: LuraDownloadRequirement)
func getRequirements() -> LuraDownloadRequirement
}

Create LuraOfflineManager

LuraOfflineManager conforms LuraOfflineManagerProtocol

private let offlineManager = LuraOfflineManager()

Create LuraOfflineEventListener


private lazy var offlineListener: LuraOfflineEventListener = { [weak self] eventBundle in

DispatchQueue.main.async {

guard let self else { return }

switch eventBundle.event {
case .COMPLETED:
case .DOWNLOADING:
case .FAILED:
case .LICENSE_UPDATED:
case .LICENSE_UPDATING:
case .LICENSE_UPDATING_FAILED:
case .PAUSED:
case .PAUSED_ALL:
case .PAUSED_BY_REQUIREMENTS:
case .PROGRESS:
case .QUEUED:
case .REMOVED:
case .REMOVING:
case .REMOVING_ALL:
case .RESTARTING:
case .RESUMED_ALL:
case .STARTING:
case .STOPPED:
case .WARNING:
default:
break
}
}
}

Add listener

Sets the event listener of the LuraOfflineManager.

offlineManager.addListener(offlineListener)

Listener id is returned during setting the offline listener operation.


// - Define Offline Listener Related Variable's
var listenerId: String? = nil
private lazy var offlineListener: LuraOfflineEventListener = { [weak self] eventBundle in

// - EventBundle consists of two type's -> (Event, Data)

DispatchQueue.main.async {

guard let self else { return }

switch eventBundle.event {

// Case handling for event here
}
}
}

// - Hold the Listener ID to refer to it
listenerId = offlineManager.addListener(listener: offlineListener)

Remove listener

Remove the event listener of the LuraOfflineManager by providing listener id.

offlineManager.removeListener(listenerId: listenerId)
Deallocation Usage
deinit {
offlineManager.removeListener(listenerId: listenerId)
listenerId = nil
}

Set Network Requirements

  • Use the LuraDownloadRequirement enum value in LuraOfflineManager::setRequirements() function.
Set Network Requirements Example
offlineManager?.setRequirements(requirements: .ANY)
// or use
offlineManager?.setRequirements(requirements: .CELLULAR)
// or use
offlineManager?.setRequirements(requirements: .WIFI)

Get Network Requirements

Returns LuraDownloadRequirement enum value in LuraOfflineManager::getRequirements() function.

Get Current Network Requirements Example
offlineManager.getRequirements()

Set Max Parallel Downloads

LuraOfflineManager().maxParallelDownloads = 3

Get Max Parallel Downloads

Returns count of max parallel downloads.

let maxNumberOfParalleDownloads = LuraOfflineManager().maxParallelDownloads

Download asset with given LuraPlayerConfiguration

When the user selects an asset to make available for offline playback, kickoff the process via downloadAsset(config: LuraPlayerConfiguration)

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
offlinePlaybackLuraOfflineConfigurationLuraOfflineConfiguration can be used to configure the video resolution. Default resolution: HD.
  • Create a LuraPlayerConfiguration object.
  • Use the newly created LuraPlayerConfiguration object in LuraOfflineManager::download() function.
Download asset example
let luraPlayerConfiguration = LuraPlayerConfiguration(
lura = Lura(
appKey = "APP_KEY",
assetId = "ASSET_ID"
),
offline = LuraOfflineConfiguration(resolution = LuraOfflineVideoResolution.HD)
)
offlineManager.download(config = luraPlayerConfiguration)

Pause downloading with given LuraPlayerConfiguration

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
  • Use the LuraPlayerConfiguration object in LuraOfflineManager::pause() function.
Pause downloading example
offlineManager.pause(config = luraPlayerConfiguration)

Pause all downloading

Pause all downloading example
offlineManager.pauseAll()

Resume downloading with given luraPlayerConfiguration

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
  • Use the LuraPlayerConfiguration object in LuraOfflineManager::resume() function.
Resume downloading example
offlineManager.resume(config = luraPlayerConfiguration)

Resume all downloading

Resume all downloading example
offlineManager.resumeAll()

Delete asset with given LuraPlayerConfiguration

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
  • Use the LuraPlayerConfiguration object in LuraOfflineManager::remove() function.
Delete asset example
offlineManager.remove(config = luraPlayerConfiguration)

Get array of downloaded assets

Returns an array of downloaded LuraOfflineVideo objects in LuraOfflineManager::getVideos() function.

Get array of downloaded assets example
let videos = offlineManager.getVideos()

Get downloaded assets

Returns a downloaded LuraOfflineVideo object in LuraOfflineManager::getVideo() function.

Get downloaded asset example
let luraPlayerConfiguration = LuraPlayerConfiguration(
lura = Lura(
appKey = "APP_KEY",
assetId = "ASSET_ID"
)
)
let offlineVideo: LuraOfflineVideo = offlineManager.getVideo(config = luraPlayerConfiguration)

Set downloaded asset with given LuraPlayerConfiguration

When the user selects an asset to make available for offline playback, kickoff the process via download(config: LuraPlayerConfiguration)

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
  • Use the LuraPlayerConfiguration object in LuraPlayer::setConfig() function.
Play downloaded asset example
 let luraPlayerConfiguration = LuraPlayerConfiguration(
lura: Lura(
appKey: "APP_KEY",
assetId: "ASSET_ID"
),
offline: LuraOfflineConfiguration(
playWhenAvailable: true
)
)

player.setConfig(config = luraPlayerConfiguration)

Get DRM license information for downloaded asset

AttributeTypeDescription
licenseLuraOfflineVideoLicenseDRM license information
license.licenseExpirationDateDoubleLicense expiration duration in seconds (if available, otherwise -1)
license.totalPlaybackDurationDoubleTotal playback duration in seconds (if available, otherwise -1)
Getting DRM license information example
let video = offlineManager.getVideo(config: luraPlayerConfiguration)

guard let videoLicenseInfo: LuraOfflineVideoLicense = video?.license else { return }

let licenseExpirationDate = videoLicenseInfo.licenseExpirationDate
let totalPlaybackDuration = videoLicenseInfo.totalPlaybackDuration

Update DRM license for downloaded asset with given LuraPlayerConfiguration

When DRM license has been expired, you can update it without re-downloading the video.

AttributeTypeDescription
configLuraPlayerConfigurationLura Configuration the same as for regular playback
  • Use the LuraPlayerConfiguration object in LuraOfflineManager::updateLicense() function.
Play downloaded asset example
offlineManager.updateLicense(config = luraPlayerConfiguration)