Skip to main content

Offline Downloads

We'll explore the workflow in this document.The Sample Android App on Github provides code examples for a typical use case.

Enable Download support

Create TpInitParams with .enableDownloadSupport(true) to enable download support.

var parameters = TpInitParams.Builder()
.setVideoId(videoId)
.setAccessToken(accessToken)
.enableDownloadSupport(true)
.build()

Creating a TpStreamsDownloadManager

The following code snippet demonstrates how to instantiate a TpStreamsDownloadManager

val tpStreamDownloadManager : TpStreamDownloadManager = TpStreamDownloadManager(activityContext)

Using this TpStreamDownloadManager we can get a list of downloaded media and the following media operations to delete, pause, resume, and cancel.

Get list of downloaded media

val downloads : LiveData<List<Video>?> = tpStreamDownloadManager.getAllDownloads()

It will return a list of OfflineVideoInfo in LiveData to monitor the download progress use ViewModel and observe.

Delete

tpStreamDownloadManager.deleteDownload(video)

Pause

tpStreamDownloadManager.pauseDownload(video)

Resume

tpStreamDownloadManager.resumeDownload(video)

Cancel

tpStreamDownloadManager.cancelDownload(video)

Delete All

tpStreamDownloadManager.deleteAllDownload()

Playing downloaded media

Create offline params and pass them to player activity via intent to play an offline video.

val intent = Intent(activityContext,PlayerActivity::class.java)
intent.putExtra(TP_OFFLINE_PARAMS,TpInitParams.createOfflineParams(video.videoId))
startActivity(intent)