Offline Playback
SDK and services support offline playback with or without DRM on Android platforms.
Creating a LuraDownloadService
To create a LuraDownloadService, you need to subclass it.
class AppDownloadService : LuraDownloadService() {
private val listener: LuraOfflineEventListener = LuraOfflineEventListener {
}
override fun onCreate() {
super.onCreate()
offlineManager.addListener(listener)
}
override fun onDestroy() {
offlineManager.removeListener(listener)
super.onDestroy()
}
}
Add service and permissions to AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
...
<service
android:name="androidx.media3.exoplayer.scheduler.PlatformScheduler$PlatformSchedulerService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name="YOUR_PACKAGE_NAME.AppDownloadService"
android:exported="false"
android:foregroundServiceType="dataSync">
<intent-filter>
<action android:name="androidx.media3.exoplayer.downloadService.action.RESTART" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
</manifest>
Create LuraOfflineManager
LuraOfflineManager.clazz = AppDownloadService::class.java
private val offlineManager = LuraOfflineManager(context = context)
Create LuraOfflineEventListener
val listener: LuraOfflineEventListener = LuraOfflineEventListener { event ->
when (event.type) {
LuraOfflineEventType.QUEUED -> {}
LuraOfflineEventType.STOPPED -> {}
LuraOfflineEventType.PAUSED -> {}
LuraOfflineEventType.PAUSED_BY_REQUIREMENTS -> {}
LuraOfflineEventType.STARTING -> {}
LuraOfflineEventType.DOWNLOADING -> {}
LuraOfflineEventType.PROGRESS -> {}
LuraOfflineEventType.COMPLETED -> {}
LuraOfflineEventType.FAILED -> {}
LuraOfflineEventType.REMOVING -> {}
LuraOfflineEventType.REMOVING_ALL -> {}
LuraOfflineEventType.REMOVED -> {}
LuraOfflineEventType.RESUMED_ALL -> {}
LuraOfflineEventType.PAUSED_ALL -> {}
LuraOfflineEventType.RESTARTING -> {}
LuraOfflineEventType.LICENSE_UPDATING -> {}
LuraOfflineEventType.LICENSE_UPDATED -> {}
LuraOfflineEventType.LICENSE_UPDATING_FAILED -> {}
}
}
Add listener
Sets the event listener of the LuraOfflineManager.
offlineManager.addListener(listener)
Remove listener
Remove the event listener of the LuraOfflineManager.
offlineManager.removeListener(listener)
Set Network Requirements
- Use the
LuraDownloadRequirement
enum value inLuraOfflineManager::setRequirements()
function.
offlineManager.setRequirements(requirements = LuraDownloadRequirement.CELLULAR)
// or
offlineManager.setRequirements(requirements = LuraDownloadRequirement.WIFI)
// or
offlineManager.setRequirements(requirements = LuraDownloadRequirement.ANY)
Get Network Requirements
Returns LuraDownloadRequirement
enum value in LuraOfflineManager::getRequirements()
function.
offlineManager.getRequirements()
Set Max Parallel Downloads
offlineManager.maxParallelDownloads = 3
Get Max Parallel Downloads
Returns count of max parallel downloads.
val maxParallelDownloads = offlineManager.maxParallelDownloads
Download asset with given LuraConfiguration
When the user selects an asset to make available for offline playback, kickoff the process via downloadAsset(config: LuraConfiguration)
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
offlinePlayback | LuraOfflineConfiguration | LuraOfflineConfiguration can be used to configure the video resolution. Default resolution: HD. |
- Create a
LuraConfiguration
object. - Use the newly created
LuraConfiguration
object inLuraOfflineManager::download()
function.
val luraConfiguration = LuraConfiguration(
lura = Lura(
appKey = "APP_KEY",
assetId = "ASSET_ID"
),
offlinePlayback = LuraOfflineConfiguration(resolution = LuraOfflineVideoResolution.HD)
)
offlineManager.download(config = luraConfiguration)
Pause downloading with given LuraConfiguration
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraConfiguration
object inLuraOfflineManager::pause()
function.
offlineManager.pause(config = luraConfiguration)
Pause all downloading
offlineManager.pauseAll()
Resume downloading with given LuraConfiguration
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraConfiguration
object inLuraOfflineManager::resume()
function.
offlineManager.resume(config = luraConfiguration)
Resume all downloading
offlineManager.resumeAll()
Delete asset with given LuraConfiguration
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraConfiguration
object inLuraOfflineManager::remove()
function.
offlineManager.remove(config = luraConfiguration)
Get array of downloaded assets
Returns an array of downloaded LuraOfflineVideo
objects in LuraOfflineManager::getVideos()
function.
val offlineVideos: List<LuraOfflineVideo> = offlineManager.getVideos()
Get downloaded assets
Returns a downloaded LuraOfflineVideo
object in LuraOfflineManager::getVideo()
function.
val luraConfiguration = LuraConfiguration(
lura = Lura(
appKey = "APP_KEY",
assetId = "ASSET_ID"
)
)
val offlineVideo: LuraOfflineVideo = offlineManager.getVideo(config = luraConfiguration)
Set downloaded asset with given LuraConfiguration
When the user selects an asset to make available for offline playback, kickoff the process via download(config: LuraConfiguration)
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraConfiguration
object inLuraPlayer::setConfig()
function.
val luraConfiguration = LuraConfiguration(
lura = Lura(
appKey = "APP_KEY",
assetId = "ASSET_ID"
),
offlinePlayback = LuraOfflineConfiguration(
playWhenAvailable = true
)
)
player.setConfig(config = luraConfiguration)
Get DRM license information for downloaded asset
Attribute | Type | Description |
---|---|---|
license | LuraOfflineVideoLicense | DRM license information |
license.licenseExpirationDate | Long | License expiration duration in seconds (if available, otherwise -1) |
license.totalPlaybackDuration | Long | Total playback duration in seconds (if available, otherwise -1) |
val video = offlineManager.getVideo(config = LuraConfiguration())
// withDRMLicense() function should not be called from Main thread.
val videoWithDRMInfo = video.withDRMLicense()
val license: LuraOfflineVideoLicense? = videoWithDRMInfo.license
val licenseExpirationDate = license?.licenseExpirationDate
val totalPlaybackDuration = license?.totalPlaybackDuration
Update DRM license for downloaded asset with given LuraConfiguration
When DRM license has been expired, you can update it without re-downloading the video.
Attribute | Type | Description |
---|---|---|
config | LuraConfiguration | Lura Configuration the same as for regular playback |
- Use the
LuraConfiguration
object inLuraOfflineManager::updateLicense()
function.
offlineManager.updateLicense(config = luraConfiguration)