Adding CONNECT Player to your application
Update the build.gradle
The illustrations below show how to modify the build.gradle to work with the CONNECT Player SDK for Android. For the list of dependencies, latest versions and build configuration, see CONNECT Player SDK 5 for Android Documentation.
In Project view, select app > src and open the build.gradle file. In the
android
block, change theminSdkVersion
to 21.android { compileSdkVersion 30 defaultConfig { applicationId "com.example.myapplication" minSdkVersion 21 targetSdkVersion 30
GROOVYAdd the following lines to the
android
block (if not already present):compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
GROOVYMake sure there is a dependency set for the latest gradle plugin in the
buildScript
block. For example:buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.0.2' } }
GROOVY- In the
dependencies
block:- Change the
implementation fileTree(dir: 'libs', include: ['*.jar'])
filetype to['*.aar']
. - Add the dependency
androidx.appcompat:appcompat:1.2.0
. - Add the dependency
com.google.guava:guava:27.1-android
.
dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) implementation 'androidx.appcompat:appcompat:1.2.0' implementation ("com.google.guava:guava:27.1-android") { exclude group: 'com.google.code.findbugs', module: 'jsr305' exclude group: 'org.checkerframework', module: 'checker-compat-qual' exclude group: 'com.google.errorprone', module: 'error_prone_annotations' exclude group: 'com.google.j2objc', module: 'j2objc-annotations' exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations' } }
GROOVY - Change the
On completion, sync the build.gradle.
Edit the MainActivity.java
Add 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 and open the MainActivity.java file. Add the following imports:
import nagra.otv.sdk.OTVSDK; import nagra.otv.sdk.OTVVideoView;
JAVABelow the line
public class MainActivity extends AppCompatActivity {
add:static final String TAG = "MainActivity"; private OTVVideoView mOTVVideoView = null; private int mPausePos = 0; private String mVideoURI = "https://d3bqrzf9w11pn3.cloudfront.net/basic_dash_bbb_clear/bbb_public.mpd";
CODEReplace the contents of the
onCreate
method with the following to set a reference to the video view and load the SDK.@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OTVSDK.load(this); setContentView(R.layout.activity_main); mOTVVideoView = findViewById(R.id.otvVideoView); }
JAVAOTVSDK.load(Context context);
must be called before accessing any SDK 5 methods as it starts up the libraries. The method needs to be called only once at application start-up or before the first use of the SDK.Add the following to set the Android
onStart
method, set the stream and start it.@Override public void onStart() { super.onStart(); mOTVVideoView.setVideoPath(mVideoURI); mOTVVideoView.start(); }
JAVAAdd the following to set the Android
onPause
method to save the current position and pause the playback.@Override public void onPause() { super.onPause(); if(mOTVVideoView != null) { mPausePos = mOTVVideoView.getCurrentPosition(); mOTVVideoView.pause(); } }
JAVAAdd the following to set the Android
onResume
method, to seek to the paused position and start playback.@Override public void onResume() { super.onResume(); if(mOTVVideoView != null && mPausePos > 0) { mOTVVideoView.seekTo(mPausePos); mPausePos = 0; } }
JAVA
Add a video view to the layout
- Select app > src > main > res > layout and open the activity_main.xml file.
In the Text view window, create a
nagra.otv.sdk.OTVVideoView
by replacing the contents with:<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <nagra.otv.sdk.OTVVideoView android:id="@+id/otvVideoView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:descendantFocusability="afterDescendants" /> </android.support.constraint.ConstraintLayout>
XML
The OTVVideoView
element works as the foremost UI element when part of a layout. Placing any other elements on top of the video view’s area will produce unpredictable effects, and may interfere with the built-in security measures.
Next step: You should now be able to run the app in clear playback mode.