ExoPlayer for Android
The easiest way to play DRM-protected videos on Android devices is to use ExoPlayer. The logical choice is to use Google Widevine with MPEG-DASH, because it is supported natively on Android devices.
You can configure ExoPlayer with a few lines of code to use Axinom DRM License Service. In a nutshell, you need to do two things to connect ExoPlayer with Axinom DRM:
- Point it to the right Axinom Widevine License Service URL
- Attach an Axinom DRM License Service Message (aka "license token") to each request
ExoPlayer takes care of the rest, including generating a proper license request and adding the needed keyId(s) to it.
You can find more detailed instructions and available options below.
ExoPlayer Demo Application​
ExoPlayer comes with a simple Demo Application.
To make this application work with Axinom DRM, adjust the media.exolist.json
configuration file by setting the correct values for drm_license_uri
and
specifying a custom license request header that carries the license token via
the drm_key_request_properties
object.
You can find the valid drm_license_uri
for your tenant from
My Mosaic area.
{
"name": "AxinomDemoVideo-SingleKey",
"uri": "https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd",
"drm_scheme": "widevine",
"drm_license_uri": "https://drm-widevine-licensing.axprod.net/AcquireLicense",
"drm_key_request_properties": {
"X-AxDRM-Message": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjogMSwiY29tX2tleV9pZCI6ICI3YjVkYmIwNC0xYzY3LTRlNjQtYWIyZS1hZTIyMDBkZmY5NzAiLCJtZXNzYWdlIjogeyAgInR5cGUiOiAiZW50aXRsZW1lbnRfbWVzc2FnZSIsICAidmVyc2lvbiI6IDIsICAiY29udGVudF9rZXlzX3NvdXJjZSI6IHsgICAgImlubGluZSI6IFsgICAgICB7ICAgICAgICAiaWQiOiAiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwgICAgICAgICJlbmNyeXB0ZWRfa2V5IjogInZzRTdGakNWZE83T2VpQ21xNFhKUmc9PSIgICAgICB9ICAgIF0gIH19fQ.WOa2ZjpbMASDEyDfER3y0A5K1JzV0bcRo6qig7Zfb7I"
}
}
The table below includes some important information about the JSON file elements.
Element | Notes |
---|---|
"uri" | Replace with a URL to your MPEG-DASH manifest. |
"drm_license_uri" | The example indludes the URL for the Test environment of Axinom DRM. For production, use https://drm-widevine-licensing.axprod.net/AcquireLicense |
"X-AxDRM-Message" | Replace with your Axinom DRM License Message ("license token"). |
To generate a test token, you can use the Entitlement Message Tool.
Custom ExoPlayer-Based Application​
In custom ExoPlayer-based applications, the integration points are the same. The only difference with the ExoPlayer Demo application is that the same functional changes illustrated by the ExoPlayer Demo configuration adjustment that handles the MediaSource creation need to be implemented in the code.
Below, we provide a functional code sample for the MediaSource creation that enables playback with Axinom DRM:
// Defining content URI, license server URI and license token.
private String mContentUri = "https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd";
private String mLicenseServer = "https://drm-widevine-licensing.axprod.net/AcquireLicense";
private String mLicenseToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjogMSwiY29tX2tleV9pZCI6ICI3YjVkYmIwNC0xYzY3LTRlNjQtYWIyZS1hZTIyMDBkZmY5NzAiLCJtZXNzYWdlIjogeyAgInR5cGUiOiAiZW50aXRsZW1lbnRfbWVzc2FnZSIsICAidmVyc2lvbiI6IDIsICAiY29udGVudF9rZXlzX3NvdXJjZSI6IHsgICAgImlubGluZSI6IFsgICAgICB7ICAgICAgICAiaWQiOiAiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwgICAgICAgICJlbmNyeXB0ZWRfa2V5IjogInZzRTdGakNWZE83T2VpQ21xNFhKUmc9PSIgICAgICB9ICAgIF0gIH19fQ.WOa2ZjpbMASDEyDfER3y0A5K1JzV0bcRo6qig7Zfb7I";
// Creating a player instance and preparing it with the built media source
private void initializePlayer() {
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
SimpleExoPlayer player = new SimpleExoPlayer.Builder(this, renderersFactory).build();
MediaSource mediaSource = buildMediaSource(this, mContentUri, mLicenseServer, mLicenseToken);
player.setMediaSource(mediaSource);
player.prepare();
}
// A method for building MediaSource.
private MediaSource buildMediaSource(Context context, String videoUrl, String licenseServer, String licenseToken) {
String userAgent = Util.getUserAgent(context, "DRM example app");
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
return new DashMediaSource.Factory(
new DefaultDashChunkSource.Factory(dataSourceFactory), dataSourceFactory)
.setDrmSessionManager(buildDrmSessionManager(userAgent, licenseServer, licenseToken))
.createMediaSource(new MediaItem.Builder().setUri(videoUrl).build());
}
// A method for building DrmSessionManager.
private DefaultDrmSessionManager buildDrmSessionManager(String userAgent, String licenseUrl, String drmToken) {
HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
new DefaultHttpDataSourceFactory(userAgent, null));
// Here the license token is attached to license request
if (drmToken != null) {
drmCallback.setKeyRequestProperty("X-AxDRM-Message", drmToken);
}
return new DefaultDrmSessionManager.Builder()
.setUuidAndExoMediaDrmProvider(C.WIDEVINE_UUID, FrameworkMediaDrm.DEFAULT_PROVIDER)
.build(drmCallback);
}
Axinom Sample Player​
Additionally, Axinom offers a Sample Player application in source code to illustrate the DRM integration. The application provides a starting point for developers who want to implement a player application that includes support for Axinom DRM and offline playback. Details about the integration of Axinom DRM are well documented in the source code.
Axinom Sample Player also demonstrates the so-called Offline Playback, i.e. how you can download the DRM-protected videos to your device, request a persistent DRM License and play the videos later without an Internet connection.
The Sample Player’s source code is available on Github.