


{"id":11080,"date":"2017-09-08T22:14:45","date_gmt":"2017-09-08T22:14:45","guid":{"rendered":"https:\/\/expressplay.local\/?page_id=11080"},"modified":"2021-07-09T09:53:00","modified_gmt":"2021-07-09T16:53:00","slug":"tutorial-android-app","status":"publish","type":"page","link":"https:\/\/www.expressplay.com\/ja\/developer\/tutorial-android-app\/","title":{"rendered":"Tutorial: Android App"},"content":{"rendered":"<style type=\"text\/css\">\n<p>    hr, img {\n        margin: 20px auto;\n    }<\/p>\n<p>    code {\n        word-break: break-all;\n        white-space: pre-wrap;\n        font-size: 14px;\n        color: #555;\n        margin: 20px 0;\n    }\n<\/style>\n<div class=\"flex flex-wrap -mx-6\">\n<div class=\"w-full lg:w-7\/12 px-6\">\n<h2>Android App Tutorial<\/h2>\n<h4 style=\"font-size:18px; font-weight: 400;\">This tutorial guides you through the process of creating a simple ExpressPlay-enabled app to play encrypted video streams using a Marlin MS3 token.<\/h4>\n<div class=\"bg-grey-100 p-8 mb-12 mt-12\">\n<h4 style=\"margin-bottom: 10px; font-weight: 400; font-size: 20px;\">Recommended equipment:<\/h4>\n<ul class=\"tutorial_container\">\n<li>A device that runs on Android 4.0.X or higher<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"w-full lg:w-5\/12 px-6\">\n      <img decoding=\"async\" src=\"\/wp-content\/uploads\/2017\/08\/developer-sdk-large.png\" alt=\"Developer SDK large\"\/>\n<\/div>\n<\/div>\n<hr \/>\n<div class=\"mb-12 mt-12\">\n<p>STEP 1 &#8211; Install the Android SDK<\/p>\n<\/div>\n<p><span style=\"font-size:15px\">If you don&#8217;t already have the Android SDK. You can download the SDK <\/span><a target=\"_blank\" href=\"http:\/\/developer.android.com\/sdk\/index.html\" rel=\"noopener noreferrer nofollow\">here<\/a><span style=\"font-size:15px\">. The remainder of this example assumes the use of the Eclipse based IDE included in the Android ADT Bundle.<\/span><\/p>\n<hr \/>\n<div class=\"mb-12 mt-12\">\n<div><span><\/span>STEP 2<\/div>\n<p>Download the latest ExpressPlay SDK<\/p>\n<\/div>\n<p>The latest version of the ExpressPlay SDK can be download from the <a class=\"underline\" target=\"_blank\" href=\"https:\/\/admin.expressplay.com\/sdk\/\" rel=\"noopener noreferrer nofollow\">ExpressPlay Admin Portal<\/a>.<\/p>\n<p>Be sure to remember where you saved your file.<\/p>\n<hr \/>\n<div class=\"mb-12 mt-12\">\n<p>STEP 3 &#8211; Import the Desired Example Project from the ExpressPlay SDK<\/p>\n<\/p><\/div>\n<p>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.  <\/p>\n<p style=\"margin-left: 40px;\">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.<\/p>\n<p><span>The &#8220;import&#8221; will place the wasabi.jar and the required native libraries (.so files) so that the project compiles. <\/span><span>Later on, when you create your own first project, you will want to replicate this structure.<\/span><\/p>\n<p>If using Eclipse:<\/p>\n<ul dir=\"ltr\">\n<li>you may need to &#8220;clean and rebuild&#8221; the project so that the Android generated files are correctly referenced<\/li>\n<li>should the wasabi references not be resolved, you may need to do the following:<\/li>\n<li>\n<p><span style=\"font-size:15px\">Click on <\/span><strong>Java Build Path<\/strong><span style=\"font-size:15px\">. Then navigate to <\/span><strong>Libraries<\/strong><span style=\"font-size:15px\"> and click on <\/span><strong>Add External JARs<\/strong><span style=\"font-size:15px\">. Select the<\/span><span style=\"font-size:15px\"> <\/span><em>wasabi.jar<\/em><span style=\"font-size:15px\"> file. The file should now appear in the build path. Next expand the <\/span><em>wasabi.jar<\/em><span style=\"font-size:15px\"> file and click <\/span><strong>Native library location<\/strong><span style=\"font-size:15px\"> and then click <\/span><strong>Edit<\/strong><span style=\"font-size:15px\">.<\/span><span style=\"font-size:15px\"> Select the libs folder.  <\/span>The external libraries should now appear in the package explorer under <strong>Referenced Libraries<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p>If using Android Studio:<\/p>\n<ul dir=\"ltr\">\n<li>you will find a record of the import, indicating the project layout required by Android Studio.  You should see the following record of import:<\/li>\n<\/ul>\n<p style=\"margin-left: 40px;\">* AndroidManifest.xml =&gt; app\/src\/main\/AndroidManifest.xml<br \/>* libs\/armeabi-v7a\/libWasabiJni.so =&gt; app\/src\/main\/jniLibs\/armeabi-v7a\/libWasabiJni.so<br \/>* libs\/armeabi\/libWasabiJni.so =&gt; app\/src\/main\/jniLibs\/armeabi\/libWasabiJni.so<br \/>* libs\/mips\/libWasabiJni.so =&gt; app\/src\/main\/jniLibs\/mips\/libWasabiJni.so<br \/>* libs\/wasabi.jar =&gt; app\/libs\/wasabi.jar<br \/>* libs\/x86\/libWasabiJni.so =&gt; app\/src\/main\/jniLibs\/x86\/libWasabiJni.so<br \/>* res\/ =&gt; app\/src\/main\/res\/<br \/>* src\/ =&gt; app\/src\/main\/java\/<\/p>\n<ul dir=\"ltr\">\n<li>the import will also create a gradle dependency statement referencing wasabi.jar<\/li>\n<\/ul>\n<p>Once the project is imported, it should compile and execute on a device or the emulator.<\/p>\n<hr \/>\n<p>The Example&#8217;s MainActivity includes several imports, the relevant ones being:<\/p>\n<ul dir=\"ltr\">\n<li>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&#8217;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<\/li>\n<li>Wasabi Runtime: the Runtime is used to initialize the DRM engine and to invoke methods to personalize the client and acquire licenses if necessary<\/li>\n<li>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.<\/li>\n<\/ul>\n<div class=\"bg-grey-100 p-8 mt-12 mb-12\">\n          <code><br \/>\nimport android.app.Activity;<br \/>\nimport android.net.Uri;<br \/>\nimport android.os.Bundle;<br \/>\nimport android.view.Menu;<br \/>\nimport android.widget.MediaController;<br \/>\nimport android.widget.VideoView;<\/p>\n<p>import com.intertrust.wasabi.ErrorCodeException;<br \/>\nimport com.intertrust.wasabi.Runtime;<br \/>\nimport com.intertrust.wasabi.media.PlaylistProxy;<br \/>\nimport com.intertrust.wasabi.media.PlaylistProxy.MediaSourceParams;<br \/>\nimport com.intertrust.wasabi.media.PlaylistProxy.MediaSourceType;<br \/>\n    <\/code>\n        <\/div>\n<hr \/>\n<p>The Activity&#8217;s onCreate() method does all the work:<\/p>\n<ul dir=\"ltr\">\n<li>creates the VideoView<\/li>\n<li>initializes the wasabi Runtime<\/li>\n<li>Checks whether the client is &#8220;personalized&#8221; (eg has acquired the necessary credentials to be recognized by services as a legitimate marlin drm client), and if not does the personalization<\/li>\n<li>creates a PlaylistProxy object and starts it (essentially an HTTP server that will serve the HLS stream to the VideoView object)<\/li>\n<li>creates a PlaylistProxy URL (the URL of the decrypted HLS stream), and passes it to the VideoView object<\/li>\n<li>starts the VideoView object to render the decrypted video<\/li>\n<\/ul>\n<div class=\"bg-grey-100 p-8 mt-12 mb-12\">\n          <code><br \/>\n    \/\/ create a MediaController for the video view<br \/>\n    VideoView videoView = (VideoView)findViewById(R.id.videoView1);<br \/>\n    MediaController mediaController = new MediaController(this, false);<br \/>\n      mediaController.setAnchorView(videoView);<br \/>\n      videoView.setMediaController(mediaController);<\/p>\n<p>      try {<br \/>\n        \/\/ initialize the Wasabi runtime (this only needs to be done once per app)<br \/>\n      Runtime.initialize(getDir(\"wasabi\", MODE_PRIVATE).getAbsolutePath());<br \/>\n      if (!Runtime.isPersonalized()) {<br \/>\n        \/\/ NOTE: in this small example we perform this personalization step<br \/>\n        \/\/ in the main thread, but it would be much better to do it in<br \/>\n        \/\/ a separate thread (asynchronously) so as to not block the user<br \/>\n        \/\/ interface while this operation completes<br \/>\n        Runtime.personalize();<br \/>\n      }<\/p>\n<p>      \/\/ create a playlist proxy and start it<br \/>\n      playerProxy = new PlaylistProxy();<br \/>\n      playerProxy.start();<br \/>\n      } catch (Exception e) {<br \/>\n      e.printStackTrace();<br \/>\n    } <\/p>\n<p>    try {<br \/>\n      String ms3_url = \"ENTER_VALID_URL\";<br \/>\n      String url = playerProxy.makeUrl(ms3_url,<br \/>\n                                   MediaSourceType.HLS,<br \/>\n                                   new MediaSourceParams());<br \/>\n        videoView.setVideoURI(Uri.parse(url));<br \/>\n      videoView.start();<br \/>\n    } catch (ErrorCodeException e) {<br \/>\n      e.printStackTrace();<br \/>\n    }<br \/>\n<\/code>\n        <\/div>\n<hr \/>\n<div class=\"mb-12 mt-12\">\n<p>STEP 4 &#8211; Generating a Valid MS3 URL<\/p>\n<\/p><\/div>\n<p>The following section provides a link that generates MS3 URLs for the purposes of testing the ExpressPlay SDK, a complete<br \/>\ntutorial on how to generate MS3 test tokens can be found <a href=\"\/ja\/developers\/tutorial-test-token\/\">here.<\/a><\/p>\n<p>A valid MS3 URL can be fetched here: http:\/\/content-access.intertrust-dev.com\/EXPR011\/ms3ext<\/p>\n<p>Copy the link into in a new browser window to download its contents. Then open contents in a text editor and copy the MS3 URL.\n<\/p>\n<p>Go to the <i>MainActivity.java<\/i> file and paste<br \/>\nit into the <font face=\"\u201ccourier\u201d\">String ms3_url<\/font>; replace the part that says <font face=\"\u201ccourier\u201d\">ENTER_VALID_URL<\/font> (remember to put it in quotes).<\/p>\n<p>      <img decoding=\"async\" src=\"\/wp-content\/uploads\/2017\/08\/tutorial-android1.png\" alt=\"\" style=\"margin: 20px 0; border: 1px solid #e7e7e7;\" \/><\/p>\n<hr \/>\n<div class=\"mb-12 mt-12\">\n<div><span><\/span>STEP 5<\/div>\n<p>Internet Permission<\/p>\n<\/div>\n<p><span style=\"font-size:15px\">Go to the package explorer and open <\/span><em>AndroidManifest.xml<\/em><span style=\"font-size:15px\">. Go to the actual xml code.<\/span><\/p>\n<p>      <img decoding=\"async\" src=\"\/wp-content\/uploads\/2017\/08\/tutorial-android2.png\" alt=\"\" style=\"margin: 20px 0; border: 1px solid #e7e7e7;\" \/><\/p>\n<p> To give the ExpressPlay SDK internet permission add the following code block in between<br \/>\n<font face=\"courier\">android:targetSdkVersion=&quot;17&quot;\/&gt;<\/font> and <font face=\"courier\">&lt;application<\/font><\/p>\n<div class=\"bg-grey-100 p-8 mt-12 mb-12\">\n<p><code><br \/>\n&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;\/&gt;<br \/>\n<\/code><\/p><\/div>\n<p><span style=\"font-size:15px\">Now the code is ready to be run.<\/span><\/p>\n<p>      <img decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/02\/tutorial-android3.png\" alt=\"\" style=\"margin: 20px 0; border: 1px solid #e7e7e7;\" \/><\/p>\n<p><strong>Note:<\/strong><span style=\"font-size:15px\"> 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.<\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>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 &#8211; Install the Android SDK If you don&#8217;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 download from the ExpressPlay Admin Portal. Be sure to remember where you saved your file. STEP 3 [&hellip;]<\/p>\n","protected":false},"author":124,"featured_media":0,"parent":10924,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-expressplay-developer.php","meta":{"_acf_changed":false,"footnotes":""},"tax_page_type":[512],"coauthors":[621],"class_list":["post-11080","page","type-page","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/pages\/11080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/users\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/comments?post=11080"}],"version-history":[{"count":0,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/pages\/11080\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/pages\/10924"}],"wp:attachment":[{"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/media?parent=11080"}],"wp:term":[{"taxonomy":"tax_page_type","embeddable":true,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/tax_page_type?post=11080"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.expressplay.com\/ja\/wp-json\/wp\/v2\/coauthors?post=11080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}