This page covers the minimum steps to display the player and play a video. For all available controls and properties, see Advanced Usage.
This guide uses the Kotlin + Jetpack Compose path. For a Java / XML-layout walkthrough, see Setting Up the SDK — Option B and the example at the bottom of this page.
1. Add a Layout File for the Player
InkPlayerFragment is a standard Android Fragment, so it cannot be dropped directly into a Composable function. Instead, declare it in a small XML layout file and use AndroidViewBinding to bring it into the Compose tree.
Create res/layout/player_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/player_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.inkryptvideos.android.InkPlayerFragment" />
After saving this file, rebuild your project. Android will generate a PlayerFragmentBinding class from it, which is referenced in the next step.
Android 14+ Screenshot Detection Variant
InkPlayerFragmentV34 is a subclass of InkPlayerFragment that uses the screenshot detection API introduced in Android 14 (API 34). When a screenshot is taken while the player is active, the SDK automatically reports the capture event to Inkrypt's servers - no extra code is required on your end.
To use it, replace the android:name attribute in player_fragment.xml:
<!-- Replace -->
android:name="com.inkryptvideos.android.InkPlayerFragment"
<!-- With -->
android:name="com.inkryptvideos.android.InkPlayerFragmentV34"
Everything else (binding, setParams, all player methods) works identically. This class requires API 34 or higher; if your minSdk is below 34, keep using InkPlayerFragment.
2. Embed the Player in Your Activity
Your MainActivity must extend FragmentActivity (not ComponentActivity). This is required to host Fragments alongside Compose - omitting it causes a runtime crash.
Use AndroidViewBinding to inflate the layout and obtain a reference to the Fragment:
class MainActivity : FragmentActivity() {
private var inkPlayer: InkPlayerFragment? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
YourAppTheme {
Column(modifier = Modifier.fillMaxSize()) {
// AndroidViewBinding bridges the Fragment into the Compose tree.
// PlayerFragmentBinding is auto-generated from player_fragment.xml.
AndroidViewBinding(PlayerFragmentBinding::inflate) {
// playerFragment matches the id in player_fragment.xml
inkPlayer = playerFragment.getFragment()
}
}
}
}
}
}
3. Load a Video
Call setParams() on the player reference with a Video ID and OTP from your backend. Refer to your Inkrypt Dashboard for instructions on generating a valid OTP.
private fun loadVideo() {
val params = InkInitParams.Builder()
.setVideoId("YOUR_VIDEO_ID")
.setOtp("YOUR_OTP")
.setAutoplay(true) // Start playing as soon as the player is ready
.build()
inkPlayer?.setParams(params)
}
Call this method after inkPlayer has been initialized - for example, on a button click or after your backend call returns the credentials. To play a different video, call setParams() again with a new Video ID and OTP pair.
Complete Kotlin Example
class MainActivity : FragmentActivity() {
private var inkPlayer: InkPlayerFragment? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
YourAppTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding),
horizontalAlignment = Alignment.CenterHorizontally
) {
AndroidViewBinding(PlayerFragmentBinding::inflate) {
inkPlayer = playerFragment.getFragment()
}
Button(
onClick = { loadVideo() },
modifier = Modifier.padding(top = 16.dp)
) {
Text("Play Video")
}
}
}
}
}
}
private fun loadVideo() {
val params = InkInitParams.Builder()
.setVideoId("YOUR_VIDEO_ID")
.setOtp("YOUR_OTP")
.setAutoplay(true)
// .setTolerateDeveloperMode(true) // Enable during development only
.build()
inkPlayer?.setParams(params)
}
}
Legacy Java / XML Example
For new projects, use the Kotlin Compose path above. The Java approach is deprecated.
res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:name="com.inkryptvideos.android.InkPlayerFragment"
android:id="@+id/ink_player_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:tag="PlayerFragment" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private InkPlayerFragment playerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerFragment = (InkPlayerFragment) getSupportFragmentManager()
.findFragmentById(R.id.ink_player_fragment);
}
private void playVideo() {
InkInitParams params = new InkInitParams.Builder()
.setVideoId("YOUR_VIDEO_ID")
.setOtp("YOUR_OTP")
.setAutoplay(true)
.build();
playerFragment.setParams(params);
}
}