Getting Started With the Player SDK for Android
This guide will walk you through the steps for adding a Kaltura video player to your Android mobile application, using the Kaltura Player. The library is a super-collection of all Kaltura Playkit libraries, which include the Player, Kaltura Analytics, and various Providers that can access the Kaltura Backend. Using the Kaltura Player library makes it easier to take advantage of all player capabilities.
In this Kotlin tutorial, you’ll learn how to import the Kaltura Player SDK, find the necessary credentials, and load the player with your Entry ID of choice. Because the player is focused on performance and giving you the simplest integration possible, it does not contain a UI. That being said, this guide will show you how to listen to events in order to manage the player state, as well as examples for adding play/pause buttons and a slider to the player.
If you prefer to see a Java sample, click here.
Before You Begin
You’ll need two things:
- Your Kaltura Partner ID, which can be found in the KMC under Settings>Integration Settings
- Any video entry, which can be found in the KMC as well.
Setting Up OVP Player
Begin by creating a new project in Android Studio. For this guide we chose the Fullscreen Activity Preset, to make it simpler to view the player in full-screen.
The FullScreenActivity.kt
comes pre-loaded with functions for showing and hiding the Action Bar and the Controls menu, to achieve the full-screen functionality.
Compile Options
Depending on your Compile Settings, you might get an error about Invoke-customs or supported release versions. In that case should add java 1.8 to your compile options in build.gradle
Dependencies
In your build.gradle
add the Kaltura-Player dependency:
Appication/Splash Activity
KalturaOvpPlayer should be initialized in the application class or in a splash activity before using the player.
KalturaOvpPlayer.initialize(this, OVP_PARTNER_ID, OVP_SERVER_URL)
Imports
In the FullScreenActivity.kt
, import the following:
Constants
Static variables in Kotlin
are placed in the Companion
Object, which acts as an inner singleton class that gives access to its members as direct members of the class.
In our Companion Object, we’ll declare the log-tag and Partner ID:
Class Variables
For starters you’ll need the ID of the entry, or video, that you want to display in the player. You can find this in the KMC under Content.
You’ll need an object for the Player, and you’ll also need to hold onto the Player State (for playing and pausing):
The Player
Create a new function called loadPlaykitPlayer
. This function will:
- Set configuration and behavior (auto-play set to True)
- Initialize the player
- Create a view that is determined by the size of the player using
fullscreen_content
object that was created by the Fullscreen preset - Load the media entry inside the player using OVP Provider Object
- Use built in Log object to document an error if loading the entry fails
- Set the global Player to the new one if nothing fails
- Call
addPlayerStateListener
function
Provider Options
The provider helps the player access the Kaltura backend. The entryId is checked against the API, and there is an option to pass a Kaltura Session, which is always recommended when creating a player. If your application doesn’t already generate a Kaltura Session, read this to learn more.
Create a function called buildOvpMediaOptions
. The apply
keyword in Kotlin will run the code block and pass the receiver, or in this case, mediaOptions
as this
.
State Listener
Create another function called addPlayerStateListener
. It sets the state of the player any time it changes and logs the state change.
onCreate
Let’s put all the pieces together. In the onCreate
function, you’ll need to call the functions we just created:
We removed the setOnTouchListner
for the button, and ended up with something that looks like this:
If you run the app now, you should see the player, and your video should start automatically. If you turn off the screen lock, you’ll see that the video becomes fullscreen and that the buttons disappear. Notice however that you have no way of pausing the video. We’ll need play and pause buttons.
Play and Pause
The Fullscreen project has already created two buttons for us. In this example we removed one of the buttons and called the other one playPauseButton. We also turned it into an imageButton (instead of text) so that we can use proper images from the Exo image library that we imported earlier.
The addPlayPauseButton
sets the button to rely on Player state in order to know which image to show. Meaning if the video is playing, the button should show a pause icon, and when the button is clicked, the video pauses and the image turns to a play icon.
We made a few other changes to the activity XML, like turning the view into a LinearLayout
. See full XML:
Full Sample
Gradle Dependencies for Playkit SDK
A. Kaltura Player:
This dependency can be used on client app side. If client app use this then there is no need to use Playkit, Kava, DTG and Providers dependency separately. Because it is inbuilt in Kaltura Player.
Find more here
implementation 'com.kaltura.player:tvplayer:kaltura_player_version'
Please check our Kaltura Player samples
#####B. Use Player components standalone:
If client app wants to use player and its plugins standalone then other dependecies should be added.Find more here
Please check our Playkit Samples
1. Playkit:
Core Player which handles Non-DRM/Clear and DRM content playback.
implementation 'com.kaltura.playkit:playkit:latest_version'
2. DTG (Download To Go):
Plugin which handles download of dash(including DRM) and hls streams(clear streams)
implementation 'com.kaltura.dtg:dtglib:dtg_latest_version'
3. Phoenix Provider Plugin:
If you are Kaltura customer then this plugin which handles Kaltura OTT and OVP BE api calls.
implementation 'com.kaltura.playkit:playkitproviders:latest_version'
4. IMA Ads Plugin:
Plugin which handles ads playback.
implementation 'com.kaltura.playkit:imaplugin:latest_version'
5. Kava Analytics Plugin:
Plugin for analytics.
implementation 'com.kaltura.playkit:kavaplugin:latest_version'
6. Youbora Analytics Plugin:
Plugin for Youbora analytics.
implementation 'com.kaltura.playkit:youboraplugin:latest_version'
7. Googlecast Plugin:
Plugin for content playback on Googlecast.
implementation 'com.kaltura.playkit:googlecast:latest_version'
8. VR Plugin:
Plugin for 360 or VR content playback.
implementation 'com.kaltura.playkit:vrplugin:latest_version'
If client apps want to exclude the playkit from other plugins in case they find any cyclic dependency issue on app side then simply it can exclude the tree from the relavant dependency.
######Example
implementation 'com.kaltura.playkit:anyPlugin:latest_version', {
exclude group: 'com.kaltura.playkit', module: 'playkit'
}
######Note
latest_version
can be picked up from here.
dtg_latest_version
can be picked from here
kaltura_player_version
can be picked from here