OpenTV Player SDK 4 for Android

Adding OpenTV components

Add device calibration profiles

To ensure good playback quality, this limits the bitrate depending on the hardware on which the player is running.

  1. Right-click the app folder and select New > Directory. In the New Directory window, enter the directory name assets and click OK.

  2. Right-click the assets folder and select New > File. In the New File window, enter the file name profiles.json and click OK. In the new profiles.json file, enter the following:

Java
    {
       "DeviceProfiles": {
           "Specific": [
               {
                   "Manufacturer": "",
                   "Model": "",
                   "Product": "",
                   "Device": "",
                   "Board": "",
                   "Hardware": "",
                   "Decoder": "",
                   "MaxBitRate": ""
              }
          ],
          "Generic": [
              {
                   "CpuCores": "1",
                   "CpuFreq": "600000",
                   "Neon": "0",
                   "MaxBitRate": "300000"
              }
          ]
   }

For more information, see Device Profiles.

Add a video view

  1. Select app > src > main > res > layout and open the content_main.xml file.

  2. Select the Text view window, and create a nagra.nmp.sdk.NMPVideoView by adding the following before the closing tag.

    Java
          <nagra.nmp.sdk.NMPVideoView
           android:id="@+id/nmpVideoView"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_centerInParent="true"
           android:descendantFocusability="afterDescendants" />
    
  3. Select app > src > main > res > values and add the following line to the strings.xml file.

    Java
    <string name="hello_world">Hello world!</string>
    

Editing the MainActivity.java file

This adds the minimum amount of code to enable playback of a single clear stream (identified by a hard-coded string) as soon as the app starts.

  1. Select app > src > main > java > [filename], open the MainActivity.java file and add the following import lines.

    Java
       import nagra.nmp.sdk.NMPVideoView;
       import nagra.nmp.sdk.NMPSDK;
    
  2. Add the following member variables after the opening brace of the MainActivity class. This example uses a NASA TV clear stream; you can change this to a clear stream of your choice.

    Java
       static final String TAG = "MainActivity";
       private NMPVideoView mNMPVideoView = null;
       private int mPausePos = 0;
       private String mVideoURI = "http://nasatv-lh.akamaihd.net/i/NASA_101@319270/master.m3u8";
    
  3. Delete the existing contents of the onCreate method, and add the following instead. This sets a reference to the video view and loads the OpenTV Player SDK.

    Java
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       mNMPVideoView = (NMPVideoView) findViewById(R.id.nmpVideoView);
       // It is necessary to load sdk library first before using sdk
       NMPSDK.load(getApplicationContext());
    
  4. Add the following to set the Android onStart method, set the stream and start it.

    Java
       @Override
       public void onStart()
       {
           super.onStart();
           mNMPVideoView.setVideoPath(mVideoURI);
           mNMPVideoView.start();
       }
    
  5. Add the following to set the Android onPause method to save the current position and pause the playback.

    Java
       @Override
       public void onPause()
       {
           super.onPause();
           if(mNMPVideoView != null)
           {
               mPausePos = mNMPVideoView.getCurrentPosition();
               mNMPVideoView.pause();
           }
       }
    
  6. Add the following to set the Android onResume method to seek to the paused position and start playback.

    Java
       @Override
       public void onResume()
       {
           super.onResume();
          if(mNMPVideoView != null && mPausePos > 0)
           {
               mNMPVideoView.seekTo(mPausePos);
               mPausePos = 0;
           }
       }
    

For more information, see Playback of clear content.


Next stepYou should now be able to run the app in clear playback mode.