Skip to main content

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.

LuraDownloadService example
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

AndroidManifest.xml
<?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 in LuraOfflineManager::setRequirements() function.
Set Network Requirements Example
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.

Get Current Network Requirements Example
offlineManager.getRequirements()

Set Max Parallel Downloads

Set Network Requirements Example
offlineManager.maxParallelDownloads = 3

Get Max Parallel Downloads

Returns count of max parallel downloads.

Get Current Network Requirements Example
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)

AttributeTypeDescription
configLuraConfigurationLura Configuration the same as for regular playback
offlinePlaybackLuraOfflineConfigurationLuraOfflineConfiguration can be used to configure the video resolution. Default resolution: HD.
  • Create a LuraConfiguration object.
  • Use the newly created LuraConfiguration object in LuraOfflineManager::download() function.
Download asset example
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

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

Pause all downloading

Pause all downloading example
offlineManager.pauseAll()

Resume downloading with given LuraConfiguration

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

Resume all downloading

Resume all downloading example
offlineManager.resumeAll()

Delete asset with given LuraConfiguration

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

Get array of downloaded assets

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

Get array of downloaded assets example
val offlineVideos: List<LuraOfflineVideo> = offlineManager.getVideos()

Get downloaded assets

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

Get downloaded asset example
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)

AttributeTypeDescription
configLuraConfigurationLura Configuration the same as for regular playback
  • Use the LuraConfiguration object in LuraPlayer::setConfig() function.
Play downloaded asset example
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

AttributeTypeDescription
licenseLuraOfflineVideoLicenseDRM license information
license.licenseExpirationDateLongLicense expiration duration in seconds (if available, otherwise -1)
license.totalPlaybackDurationLongTotal playback duration in seconds (if available, otherwise -1)
Getting DRM license information example
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.

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