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)
deinit {
offlineManager.removeListener(listenerId: listenerId)
listenerId = nil
}
Set Network Requirements
- Use the
LuraDownloadRequirement
enum value inLuraOfflineManager::setRequirements()
function.
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.
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)
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
offlinePlayback | LuraOfflineConfiguration | LuraOfflineConfiguration can be used to configure the video resolution. Default resolution: HD. |
- Create a
LuraPlayerConfiguration
object. - Use the newly created
LuraPlayerConfiguration
object inLuraOfflineManager::download()
function.
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
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraPlayerConfiguration
object inLuraOfflineManager::pause()
function.
offlineManager.pause(config = luraPlayerConfiguration)
Pause all downloading
offlineManager.pauseAll()
Resume downloading with given luraPlayerConfiguration
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraPlayerConfiguration
object inLuraOfflineManager::resume()
function.
offlineManager.resume(config = luraPlayerConfiguration)
Resume all downloading
offlineManager.resumeAll()
Delete asset with given LuraPlayerConfiguration
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraPlayerConfiguration
object inLuraOfflineManager::remove()
function.
offlineManager.remove(config = luraPlayerConfiguration)
Get array of downloaded assets
Returns an array of downloaded LuraOfflineVideo
objects in LuraOfflineManager::getVideos()
function.
let videos = offlineManager.getVideos()
Get downloaded assets
Returns a downloaded LuraOfflineVideo
object in LuraOfflineManager::getVideo()
function.
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)
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraPlayerConfiguration
object inLuraPlayer::setConfig()
function.
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
Attribute | Type | Description |
---|---|---|
license | LuraOfflineVideoLicense | DRM license information |
license.licenseExpirationDate | Double | License expiration duration in seconds (if available, otherwise -1) |
license.totalPlaybackDuration | Double | Total playback duration in seconds (if available, otherwise -1) |
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.
Attribute | Type | Description |
---|---|---|
config | LuraPlayerConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraPlayerConfiguration
object inLuraOfflineManager::updateLicense()
function.
offlineManager.updateLicense(config = luraPlayerConfiguration)