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.
- Right-click the app folder and select New > Directory. In the New Directory window, enter the directory name assets and click OK.
- 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:
{
"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
- Select app > src > main > res > layout and open the content_main.xml file.
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" />
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.
Select app > src > main > java > [filename], open the MainActivity.java file and add the following import lines.
JAVAimport nagra.nmp.sdk.NMPVideoView; import nagra.nmp.sdk.NMPSDK;
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.
JAVAstatic 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";
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.
JAVAsuper.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());
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(); }
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(); } }
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 step: You should now be able to run the app in clear playback mode.