CONNECT Player SDK 5 for Android
5.42.x 5.41.x 5.40.x 5.39.x 5.38.x 5.37.x 5.36.x 5.35.x 5.34.x 5.33.x 5.32.x 5.31.x 5.30.x 5.29.x 5.28.x 5.27.x 5.26.x 5.25.x 5.24.x 5.23.x 5.22.x 5.21.x 5.20.x 5.19.x 5.18.x 5.17.x 5.16.x 5.15.x 5.14.x 5.13.x 5.12.x 5.11.x 5.10.x 5.9.x 5.8.x 5.7.x 5.6.x 5.5.x
5.42.x 5.41.x 5.40.x 5.39.x 5.38.x 5.37.x 5.36.x 5.35.x 5.34.x 5.33.x 5.32.x 5.31.x 5.30.x 5.29.x 5.28.x 5.27.x 5.26.x 5.25.x 5.24.x 5.23.x 5.22.x 5.21.x 5.20.x 5.19.x 5.18.x 5.17.x 5.16.x 5.15.x 5.14.x 5.13.x 5.12.x 5.11.x 5.10.x 5.9.x 5.8.x 5.7.x 5.6.x 5.5.x

Editing the MainActivity file

Use this to 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.

Expand appsrcmainjavafilename and open the MainActivity file.

  1. Add the following imports:

    Java
        import nagra.otv.sdk.OTVSDK;
        import nagra.otv.sdk.OTVVideoView;
    
  2. Below 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";
    
  3. Replace the contents of the onCreate method with the following to set a reference to the video view and load the SDK.

    Java
        @Override
        protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          OTVSDK.load(this);
          setContentView(R.layout.activity_main);
          mOTVVideoView = findViewById(R.id.otvVideoView);
        }
    

    OTVSDK.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; either at application start-up or before the first use of the SDK.

  4. Add the following Android onStart method to set and start the stream.

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

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

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

Next step: Add a video view element to the layout.