Migrating from ExoPlayer to the Bitmovin Player
In this guide, we will show you how to migrate from ExoPlayer to the Bitmovin Player in just three simple steps.
Step 1: Add & configure your Bitmovin Player
First, add a link to our Maven repository in your application's build.gradle
or settings.gradle
file. Make sure not to remove the Google Maven repository.
allprojects {
repositories {
mavenCentral()
google()
+ maven {
+ url 'https://artifacts.bitmovin.com/artifactory/public-releases'
+ }
}
}
Next, add the Bitmovin Player as a dependency to your project as shown below:
+ implementation 'com.bitmovin.player:player:3.+'
We recommend you use the latest version of our Bitmovin Player. You can find all versions here.
Now, add the Bitmovin Player License Key to your AndroidManifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application ... >
<activity ... />
+ <meta-data android:name="BITMOVIN_PLAYER_LICENSE_KEY" android:value="<PLAYER_LICENSE_KEY>" />
</application>
</manifest>
And finally, register the package name of your application in your Bitmovin Dashboard under "Player" -> "Licenses". This security mechanism protects your license from being used elsewhere.
Step 2: Remove the ExoPlayer dependencies
In your Gradle file, remove all ExoPlayer dependencies:
- implementation com.google.android.exoplayer.*
Note
By default, an application cannot use both the Bitmovin Player and ExoPlayer as they define identical symbols. Thus, it is recommended that you migrate all ExoPlayer instances of your app to the Bitmovin Player.
Alternatively, you can use the Bitmovin+jason
variant to use both Players in the same project as described here.
Step 3: Replace ExoPlayer references in your project
User Interface
To migrate the UI, simply replace occurrences of StylePlayerView
with PlayerView
.
An example:
- <com.google.android.exoplayer2.ui.StylePlayerView
+ <com.bitmovin.player.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Learn how to customize your cross-platform Bitmovin UI here.
Replace ExoPlayer API
The APIs of ExoPlayer and Bitmovin Player are similar in functionality. As a result, the migration is mostly about changing method names and signatures.
Here is an example of creating a new Bitmovin Player:
- val player = ExoPlayer.Builder(context).build()
+ val analyticsConfig = AnalyticsConfig(licenseKey = "<ANALYTICS_LICENSE_KEY>")
+ val player = Player(context, PlayerConfig(), AnalyticsPlayerConfig.Enabled(analyticsConfig))
this.findViewById(R.id.playerView).player = player
- ExoPlayer player = new ExoPlayer.Builder(context).build();
+ AnalyticsConfig analyticsConfig = new AnalyticsConfig("<ANALYTICS_LICENSE_KEY>")
+ Player player = new PlayerBuilder(context)
+ .configureAnalytics(analyticsConfig)
+ .build()
this.findViewById(R.id.playerView).setPlayer(player);
Next, replace occurrences of MediaItem
by SourceConfig
and load your sources. Here is an example of loading a Dash stream:
val url = "https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd"
- val mediaItem = MediaItem.Builder()
- .setUrl(url)
- .setMimeType(MimeTypes.APPLICATION_MPD) // Dash
- .build();
- player.setMediaItem(mediaItem)
- player.prepare()
+ val sourceConfig = SourceConfig(url, SourceType.Dash) // or SourceConfig.fromUrl(url) to auto-detect the source type
+ val source = Source(sourceConfig)
+ player.load(source)
player.play()
String url = "https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd";
- MediaItem mediaItem = new MediaItem.Builder()
- .setUrl(url)
- .setMimeType(MimeTypes.APPLICATION_MPD) // Dash
- .build();
- player.setMediaItem(mediaItem);
- player.prepare();
+ SourceConfig sourceConfig = new SourceConfig(url, SourceType.Dash); // or SourceConfig.fromUrl(url) to auto-detect the source type
+ Source source = new SourceBuilder(sourceConfig).build();
+ player.load(source);
player.play();
Note
Android Studio will also support you by flagging errors for any other ExoPlayer code.
To support you with the further migration, we've created mapping tables between the ExoPlayer and Bitmovin Player API, which you can refer to - especially for more advanced use cases.
And that's it!
You're ready to play a video in your application using the Bitmovin Player 😀
Summary
In this guide, we demonstrated how easy it is to migrate from ExoPlayer to the Bitmovin Player in just three simple steps: adding the Bitmovin Player, removing the ExoPlayer dependencies and mapping the ExoPlayer API to the Bitmovin Player API.
Next, you can
- check out our Getting Started Guide.
- download fully working examples and explore more features in our GitHub repository.
- choose additional platforms to deploy on in our Getting Started Hub and try our no-code wizards.
- browse our Bitmovin Player API reference.
- try our Analytics product to get real-time insights into your new Android Player.
- see if some of the questions you might have are answered in our Community and ask your own!
Appendix: Mapping Tables
For more advanced use cases, we've created the following mapping tables to support your migration.
In comparison, the Bitmovin Player API is written in Kotlin and allows more expressive and terse syntax by using default values whereas ExoPlayer makes heavy use of the builder pattern.
Note
Methods and classes are only listed if their names are different.
Package mapping
ExoPlayer | Bitmovin Player |
---|---|
com.google.android.exoplayer2 | com.bitmovin.player.api |
com.google.android.exoplayer2.ui | com.bitmovin.player |
Class mapping
ExoPlayer | Bitmovin Player |
---|---|
ExoPlayer | Player |
ExoPlayer.Builder | PlayerConfig |
MediaItem | SourceConfig |
DrmConfiguration | DrmConfig |
StylePlayerView | PlayerView |
ExoPlayer
➡️ Player
method mapping
ExoPlayer
➡️ Player
method mappingExoPlayer | Bitmovin Player |
---|---|
Builder.build() | Player or PlayerBuilder.build() |
setMediaItem | load |
prepare | Not needed, done in load |
seekTo* | See the Seeking section |
release | destroy |
setMediaItems | load |
addMediaItem | PlaylistConfig or playlist.add |
moveMediaItem | playlist.remove then add |
setPlayWhenReady(true) | play |
setPlayWhenReady(false) | pause |
setDeviceMuted(true) | mute |
setDeviceMuted(false) | unmute |
*Volume | volume |
getCurrentPosition | currentTime |
getCurrentTimeline | playlist |
getCurrentTracks | source.get*Tracks |
getPlayerError | See the Events section |
isLoading | isStalled |
isPlayingAd | isAd |
isCurrentMediaItemLive | isLive |
MediaItem
➡️ Source
method mapping
MediaItem
➡️ Source
method mappingExoPlayer | Bitmovin Player |
---|---|
MediaItem.fromUri | SourceConfig.fromUrl |
MediaItem.setClippingConfiguration | Not supported |
Additional Notes
Seeking
ExoPlayer.seekTo(positionMs)
(seeking in the current source) is equivalent to:
player.seek()
for non-live streamsplayer.timeShift()
for live streams
ExoPlayer.seekTo(mediaItemIndex, positionMs)
(seeking in any source of the playlist) is equivalent to:
player.playlist.seek()
for non-live streams- Live streams are currently not supported in Playlists.
ExoPlayer has some other seek helper methods to seek in the timeline. (seekForward
, seekToDefaultPosition
, seekToNextMediaItem
, etc.).
When using the Bitmovin Player you can get the seek position using player.currentPosition
and player.playlist
.
Events
The Bitmovin Player provides an extensive Event Framework. Listening to a Player
event is as simple as:
player.on<PlayerEvent.Seek> { seekEvent ->
// ...
}
player.on(PlayerEvent.Seek.class, seekEvent ->
// ...
);
If you were using exoPlayer.addAnalyticsListener(EventLogger())
to log ExoPlayer events to the logcat, you may use the equivalent described here
For more advanced use cases, take a look at our API documentation for the EventEmitter
here.
Updated 9 months ago