Skip to main content
Skip table of contents

Unified API playback of clear content

To test this feature and view the example code, please see the Unified API Example Code Quick Start guide.

Import classes

To play clear content using the UPI, the application first needs to import the following.

JAVA
import nagra.otv.upi.*

Preparing the listener

An IOTVUPIEventListener instance should be created before creating an IOTVUPIPlayer object to receive the events from OTVUPIPlayer.

Click here to view the example code.
JAVA
public class UPIEventListener implements IOTVUPIEventListener {
    private static String TAG = "UPIEventListener";
    @Override
    public void onLoadStart(String src, String type) {
        OTVLog.d(TAG, "OnLoadStart");
    }

    @Override
    public void onLoad(long duration, int flags) {
        OTVLog.d(TAG,"onLoad "+duration);
    }

    @Override
    public void onTracksChanged(List<OTVTrackInfo> trackInfoList) {
        OTVLog.d(TAG,"onTracksChanged "+trackInfoList.toString());
    }

    @Override
    public void onProgress(long currentDuration, long playableDuration, long seekableDuration) {

    }

    @Override
    public void onSeek(long currentPosition, long seekPosition) {
        OTVLog.d(TAG,"onSeek "+currentPosition);
    }

    @Override
    public void onEnd() {
        OTVLog.d(TAG, "OnEnd");
    }

    @Override
    public void onWaiting() {
        OTVLog.d(TAG, "OnWaiting");
    }

    @Override
    public void onPlaying() {
        OTVLog.d(TAG, "OnPlaying");
    }

    @Override
    public void onPaused() {
        OTVLog.d(TAG, "OnPaused");
    }

    @Override
    public void onPlay() {
        OTVLog.d(TAG, "OnPlay");
    }

    @Override
    public void onVideoTrackSelected(int index) {
        OTVLog.d(TAG,"onVideoTrackSelected "+index);
    }

    @Override
    public void onAudioTrackSelected(int index) {
        OTVLog.d(TAG,"onAudioTrackSelected "+index);
    }

    @Override
    public void onTextTrackSelected(int index) {
        OTVLog.d(TAG, "onTextTrackSelected "+index);
    }

    @Override
    public void onError(Pair<Integer,Integer> errCodes, String errMsg) {
        OTVLog.e(TAG,"onError "+ errCodes.first +" extra "+ errCodes.second +" Msg "+ errMsg);
    }
}

Creating player

The UPI player should be created inside the method onCreate() of Activity. To create the UPI Player, the application has to invoke the static method createPlayer(Context context, OTVUPISource source, IOTVUPIEventListener eventListener) from the OTVUPIPlayerFactory.

JAVA
OTVUPISource source = new OTVUPISource(STREAM_URI, "", "", "", null, null);
IOTVUPIEventListener eventListener = new UPIEventListener(); 
mIOTVUPIPlayer = OTVUPIPlayerFactory.createPlayer(this, source, eventListener);

Setting the view

The application must set the video view to the IOTVUPIPlayer instance. To achieve this, a method setView() is invoked by passing the video view in the arguments.

JAVA
mIOTVUPIPlayer.setView(mFrame);
Click here to view the example code.
JAVA
public class MainActivity extends Activity {
  private final String STREAM_URI = "https://d3bqrzf9w11pn3.cloudfront.net/basic_dash_bbb_clear/bbb_public.mpd";
  private FrameLayout mFrame = null;
  private IOTVUPIPlayer mIOTVUPIPlayer;

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

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

    OTVUPISource source = new OTVUPISource(STREAM_URI, "", "", "", null, null);
    IOTVUPIEventListener eventListener = new UPIEventListener(); 
    mIOTVUPIPlayer = OTVUPIPlayerFactory.createPlayer(this, source, eventListener);
    if (mIOTVUPIPlayer != null) {
      mIOTVUPIPlayer.setView(mFrame);
    }
  }

  /*
   * 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);
    mIOTVUPIPlayer.onConfigurationChanged(newConfig);
  }

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

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


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.