Getting Started
The following tutorial will walk you through adding the Bitmovin Player SDK to a new or existing Android Project. If you're migrating from ExoPlayer to Bitmovin Player, check out our migration guide instead.
Step 1: Add the SDK to your Project
Add a Link to the Player SDK repository
Add a link to our release repository to your application's build.gradle
file. In addition to that, the Google Maven repository must be added.
allprojects {
repositories {
mavenCentral()
google()
maven {
url 'https://artifacts.bitmovin.com/artifactory/public-releases'
}
}
}
Add the Dependency to the Project
Add the Bitmovin Player Android SDK as a dependency to your project as shown below, while replacing {version-number}
with the desired SDK version number. The available SDK versions are listed in our release notes.
implementation 'com.bitmovin.player:player:{version-number}'
Step 2: Set up your Project
Edit the manifest file
The Bitmovin Player license key and the necessary permissions have to be added to the manifest file. The license key should be added inside the application
element.
<meta-data android:name="BITMOVIN_PLAYER_LICENSE_KEY" android:value="<PLAYER_LICENSE_KEY>" />
Alternatively, you can specify the license key in the PlayerConfig:
val playerConfig = PlayerConfig(key = "<PLAYER_LICENSE_KEY>")
The player requires the INTERNET
permission. The following line should be added inside the manifest
element.
<uses-permission android:name="android.permission.INTERNET" />
Step 3: Set up the Player
Instantiate the Player (Quick Setup)
To get started quickly with the default Bitmovin Web UI, the PlayerView can be added to the layout:
<com.bitmovin.player.PlayerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/playerView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</com.bitmovin.player.PlayerView>
Then you need to create the source:
val url = "https://cdn.bitmovin.com/content/assets/art-of-motion-dash-hls-progressive/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd"
val sourceConfig = SourceConfig(url, SourceType.Dash) // or SourceConfig.fromUrl(url) to auto-detect the source type
val source = Source.create(sourceConfig)
Finally, get the player instance in the Activity and load the source into it:
val playerView = this.findViewById(R.id.playerView)
val player = playerView.player
player?.load(source)
Instantiate the Player (Advanced Setup)
For more elaborate workflows, e.g. specific configurations, or a custom UI, the player can also be instantiated explicitly:
val playerConfig = PlayerConfig()
val player = Player.create(context, playerConfig)
This Player can then be attached to a PlayerView:
val playerView = this.findViewById(R.id.playerView)
playerView.player = player
Alternatively, a custom UI can be implemented. See the corresponding sample for details.
Finally, a source is created and loaded into the player.
val url = "https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd"
val sourceConfig = SourceConfig(url, SourceType.Dash) // or SourceConfig.fromUrl(url) to auto-detect the source type
val source = Source.create(sourceConfig)
player.load(source)
Step 4: Configure your Player License
Allowlist Application ID
In order to use the player in your app, you have to allowlist the application ID (package name) of your app. This is a security mechanism and protects your license from being used elsewhere.
Application ID allowlisting can be done in the Dashboard under Player > Licenses.
Summary
In this tutorial you've learned how to add the Bitmovin Player Android SDK to your project, set up the player license, and how configure and use the Player.
Now you can start having a look at the API reference and adapt the player to your needs.
Updated about 2 months ago