Developer Center

Android App Tutorial

This tutorial guides you through the process of creating a simple ExpressPlay-enabled app to play encrypted video streams using a Marlin MS3 token.

Recommended equipment:

  • A device that runs on Android 4.0.X or higher

STEP 1

Install the Android SDK

If you don’t already have the Android SDK. You can download the SDK here. The remainder of this example assumes the use of the Eclipse based IDE included in the Android ADT Bundle.


STEP 2

Download the latest ExpressPlay SDK

The latest version of the ExpressPlay SDK can be found here.

Be sure to remember where you saved your file.


STEP 3

Import the Desired Example Project from the ExpressPlay SDK

The SDK includes several examples. Importing the example code from the SDK will create the necessary project structure, whether you use Eclipse or Android Studio.

Prior to importing the code, copy the content of the Library/ directory (including wasabi.jar and the directories corresponding to the architectures of your choice) into the libs/ directory of the example you want to import.

The “import” will place the wasabi.jar and the required native libraries (.so files) so that the project compiles. Later on, when you create your own first project, you will want to replicate this structure.

If using Eclipse:

  • you may need to “clean and rebuild” the project so that the Android generated files are correctly referenced
  • should the wasabi references not be resolved, you may need to do the following:
  • Click on Java Build Path. Then navigate to Libraries and click on Add External JARs. Select the wasabi.jar file. The file should now appear in the build path. Next expand the wasabi.jar file and click Native library location and then click Edit. Select the libs folder. The external libraries should now appear in the package explorer under Referenced Libraries.

If using Android Studio:

  • you will find a record of the import, indicating the project layout required by Android Studio. You should see the following record of import:

* AndroidManifest.xml => app/src/main/AndroidManifest.xml
* libs/armeabi-v7a/libWasabiJni.so => app/src/main/jniLibs/armeabi-v7a/libWasabiJni.so
* libs/armeabi/libWasabiJni.so => app/src/main/jniLibs/armeabi/libWasabiJni.so
* libs/mips/libWasabiJni.so => app/src/main/jniLibs/mips/libWasabiJni.so
* libs/wasabi.jar => app/libs/wasabi.jar
* libs/x86/libWasabiJni.so => app/src/main/jniLibs/x86/libWasabiJni.so
* res/ => app/src/main/res/
* src/ => app/src/main/java/

  • the import will also create a gradle dependency statement referencing wasabi.jar

Once the project is imported, it should compile and execute on a device or the emulator.


The Example’s MainActivity includes several imports, the relevant ones being:

  • VideoView Widget: The examples use this widget as it is the simplest to render video. Starting with Lollipop, this widget does not handle HLS very well, and it is now preferable to use Android’s ExoPlayer. Nevertheless, for simplicity the examples use the VideoView widget, and an example using the ExoPlayer can be found at https://expressplay.zendesk.com/entries/81662715-Using-ExpressPlay-with-Android-Studio
  • Wasabi Runtime: the Runtime is used to initialize the DRM engine and to invoke methods to personalize the client and acquire licenses if necessary
  • PlaylistProxy: the PlaylistProxy is the main engine for decrypting video and making the decrypted video available as an HLS stream to the native video player backing the VideoView widget.
import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.widget.MediaController; import android.widget.VideoView; import com.intertrust.wasabi.ErrorCodeException; import com.intertrust.wasabi.Runtime; import com.intertrust.wasabi.media.PlaylistProxy; import com.intertrust.wasabi.media.PlaylistProxy.MediaSourceParams; import com.intertrust.wasabi.media.PlaylistProxy.MediaSourceType;

The Activity’s onCreate() method does all the work:

  • creates the VideoView
  • initializes the wasabi Runtime
  • Checks whether the client is “personalized” (eg has acquired the necessary credentials to be recognized by services as a legitimate marlin drm client), and if not does the personalization
  • creates a PlaylistProxy object and starts it (essentially an HTTP server that will serve the HLS stream to the VideoView object)
  • creates a PlaylistProxy URL (the URL of the decrypted HLS stream), and passes it to the VideoView object
  • starts the VideoView object to render the decrypted video
// create a MediaController for the video view VideoView videoView = (VideoView)findViewById(R.id.videoView1); MediaController mediaController = new MediaController(this, false); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); try { // initialize the Wasabi runtime (this only needs to be done once per app) Runtime.initialize(getDir("wasabi", MODE_PRIVATE).getAbsolutePath()); if (!Runtime.isPersonalized()) { // NOTE: in this small example we perform this personalization step // in the main thread, but it would be much better to do it in // a separate thread (asynchronously) so as to not block the user // interface while this operation completes Runtime.personalize(); } // create a playlist proxy and start it playerProxy = new PlaylistProxy(); playerProxy.start(); } catch (Exception e) { e.printStackTrace(); } try { String ms3_url = "ENTER_VALID_URL"; String url = playerProxy.makeUrl(ms3_url, MediaSourceType.HLS, new MediaSourceParams()); videoView.setVideoURI(Uri.parse(url)); videoView.start(); } catch (ErrorCodeException e) { e.printStackTrace(); }

STEP 4

Generating a Valid MS3 URL

The following section provides a link that generates MS3 URLs for the purposes of testing the ExpressPlay SDK, a complete tutorial on how to generate MS3 test tokens can be found here.

A valid MS3 URL can be fetched here. Click on the link and open its contents in a text editor, and copy the MS3 URL.

Go to the MainActivity.java file and paste it into the String ms3_url; replace the part that says ENTER_VALID_URL (remember to put it in quotes).


STEP 5

Internet Permission

Go to the package explorer and open AndroidManifest.xml. Go to the actual xml code.

To give the ExpressPlay SDK internet permission add the following code block in between android:targetSdkVersion="17"/> and <application

<uses-permission android:name="android.permission.INTERNET"/>

Now the code is ready to be run.

Note: If you are using an Android virtual machine, as opposed to an actual device, the video may not play correctly but you may hear the audio. This is due to the speed of software decoding on the virtual machine.