Skip to main content

Jetpack Compose Integration

To integrate the Vdocipher player using Jetpack Compose, follow these steps:

Step 1: Add Player Fragment

Set Up your Composable Function

Create a Composable function that uses AndroidView to host a fragment for the Vdocipher player. Retrieve the fragment instance in your activity.

 @Composable
fun AppScreen(activity: AppCompatActivity) {
AndroidView(modifier = Modifier.wrapContentHeight(), factory = { context ->
FragmentContainerView(context).apply {
id = android.R.id.content // Set an ID for the FragmentContainerView
vdoPlayerUIFragment = VdoPlayerUIFragment()
activity.supportFragmentManager.commit {
replace(id, vdoPlayerUIFragment) // Replace or add the fragment
}
}
})
}
Want to create custom controls?

If you want to create custom controls, disable the default controls by setting showControls="false".

    // To disable/enable player control use "showControls"
val bundle = Bundle()
bundle.putBoolean("showControls", false)

vdoPlayerUIFragment = VdoPlayerUIFragment().apply {
arguments = bundle
}
activity.supportFragmentManager.commit {
replace(id, vdoPlayerUIFragment) // Replace or add the fragment
}

Step 2: Initializing the Player and Starting Playback

Initialize the Player:

Ensure that the VdoPlayerUIFragment is successfully attached to the UI window before initializing the player. Start by obtaining a VdoPlayer instance by calling the initialize() method on the vdoPlayerUIFragment. You'll need to pass an InitializationListener to this method to receive the VdoPlayer instance.

// Once the vdoPlayerUIFragment is successfully attached to the window, initialize the listener for VdoPlayer
supportFragmentManager.registerFragmentLifecycleCallbacks(object :
FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentResumed(fm: FragmentManager, fragment: Fragment) {
super.onFragmentResumed(fm, fragment)
if(fragment is VdoPlayerUIFragment) {
vdoPlayerUIFragment.initialize(initializationListener)
}
}
}, true)

Implement the Initialization Listener:

Declare and implement the InitializationListener to handle the initialization process. In the onInitializationSuccess() callback, you’ll receive the VdoPlayer instance, which can then be used to load and play media.

val initializationListener = object : PlayerHost.InitializationListener {
override fun onInitializationSuccess(playerHost: PlayerHost, vdoPlayer: VdoPlayer, wasRestored: Boolean) {
// Build a video initialization params object to load the player with a video
val vdoInitParams = VdoInitParams.Builder()
.setOtp("REPLACE WITH YOUR OTP")
.setPlaybackInfo("REPLACE WITH YOUR PLAYBACK INFO")
.build()

// Load the player with the VdoInitParams object
vdoPlayer.load(vdoInitParams)
}

override fun onInitializationFailure(playerHost: PlayerHost, errorDescription: ErrorDescription) {
// Handle player initialization failure
}

override fun onDeInitializationSuccess() {
// Called when the vdoPlayerUIFragment is detached from the parent activity and the player is deinitialized.
}

}

Proceed with Playback Event Integration

To continue implementation with playback events, follow the guide: Listen to Playback Events.