To test this feature and view the example code, please see the Android SDK 5 Example Code Quick Start guide.

The SDK is created and initialised when the client application starts up (upon calling OTVSDK.load()) and is destroyed when the application terminates. Typically, the SDK is created by the following code within the application entry point activity onCreate() method.

OTVSDK.load(this);
JAVA

Player lifecycle

An OTVVideoView object must be created and configured to enable users to watch any content.

  1. The application follows instructions from the user to play content by providing the SDK with the URL.

    If the streaming content is served over HTTPS, you may need to disable SSL verification under certain circumstances.

  2. The application instantiates an OTVVideoView (typically through the layout definitions), and the application passes the URL using mOTVVideoView.setVideoPath(url).
  3. The player is destroyed when playback stops.

Changing streams

Streams can be changed by either:

  • Stopping playback, destroying the instance of the player and creating a new instance with a new URL.
  • Updating the existing instance of the player instructing it to use a different URL.

Stream type detection

When OtvVideoView#setVideoPath() is called, the SDK can detect the stream type by:

  • Observing the filename extension in the path (for example, .m3u8 for HLS, .manifest for DASH)
  • Sending an HTTP HEAD request and observing the returned ContentType value.

If neither of the methods can identify the stream type, playback will fail with an error. Alternatively, if the app can determine the content type from the stream metadata, it can inform the player explicitly by using mOTVVideoView.setVideoPath(String path, int contentType).

Example code

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // The OTVSDK.load() method must be called before SDK can be used
    // You may wish to do this in an application class
    OTVSDK.load(this);

    setContentView(R.layout.activity_main);
    mFrame = findViewById(R.id.frame);

    if (mOTVVideoView == null) {
      mOTVVideoView = new OTVVideoView(this);
      mOTVVideoView.setVideoPath(STREAM_URI);
      mFrame.addView(mOTVVideoView);
    }
  }

  /*
   * This code is only necessary if you want to switch between different layouts or change config
   * values such as video display area between rotations. As long as androidManifest contains
   * android:configChanges="orientation|screenSize" then your view/player should not be destroyed on rotation.
   * see https://developer.android.com/guide/topics/resources/runtime-changes for more information
   */
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (mOTVVideoView.getParent() != null) {
      ViewGroup parent = (ViewGroup) mOTVVideoView.getParent();
      parent.removeView(mOTVVideoView);
    }
    mFrame.addView(mOTVVideoView);
  }

  @Override
  public void onPause() {
    super.onPause();
    if (mOTVVideoView != null) {
      mOTVVideoView.pause();
    }
  }

  @Override
  public void onResume() {
    super.onResume();
    if (mOTVVideoView != null) {
      mOTVVideoView.start();
    }

  }
}
JAVA