Live-to-VOD transition
What you learn
You're instantiating DIVA Player in your app and relying on DIVA Back Office as the video streaming source.
The goal of this article is to build the simplest front-end to stream a video from the DIVA Back Office and manage the video transition from live to VOD.
Before starting
- Ensure the DIVA Back Office instance you rely on is up and running.
- Ask your video engineers team the
<video id>and the related<settings URL>. - Ensure the VideoMetadata contains the asset state, which is what your front-end reads to get whether the video is either live or VOD.
Instantiation
Write the Basic instantiation code, then add the code to read the assetState within the VideoMetadata:
...
divaFragment.api.video.registerListener(object : VideoCallback{
override fun onVideoEnded() {
//In this example, no implementation is required
}
override fun onVideoMetadataReceived(
old: VideoMetadataClean?,
new: VideoMetadataClean?
) {
if (old?.assetState==AssetState.vod && new?.assetState==AssetState.live)
{
//Write the front-end logic when transitioning from live to VOD <----
}
}
})
Working sample code
package com.example.divaplayerhelloworld20
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.deltatre.divaboadapter.DivaBoAdapter
import com.deltatre.divaboadapter.DivaExtraParams
import androidx.lifecycle.lifecycleScope
import com.deltatre.divacorelib.api.video.VideoCallback
import com.deltatre.divacorelib.models.AssetState
import com.deltatre.divacorelib.models.VideoMetadataClean
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val divaExtraParams = DivaExtraParams()
val boAdapter = DivaBoAdapter(this /*refers to the Activity class */, lifecycleScope)
boAdapter.createDivaFragment(
adapterSettingsUrl = "<settingsURL>",
langCountryCode = "<languageCountryCode>",
videoId = "<videoId>",
getCurrentUserAccountAccessToken = {
//Get the user token
"<userToken>"
},
sharedKey = "<sharedKey>",
conf = divaExtraParams,
onError = { exception ->
//On Error
}
)
{ divaFragment ->
supportFragmentManager
.beginTransaction()
.replace(R.id.fragment_container_view, divaFragment)
.commit()
divaFragment.api.watchTogether.buttonVisibilityChange
divaFragment.api.video.registerListener(object : VideoCallback{
override fun onVideoEnded() {
//In this example, no implementation is required
}
override fun onVideoMetadataReceived(
old: VideoMetadataClean?,
new: VideoMetadataClean?
) {
if (old?.assetState==AssetState.vod && new?.assetState==AssetState.live)
{
//Write the front-end logic when transitioning from live to VOD
}
}
})
}
}
}