Import classes
To play clear content using the UPI, the application first needs to import the following.
JAVA
import nagra.otv.upi.*
Once the packages are imported, an IOTVUPIPlayer
object is instantiated, and the UPI player is created and assigned to the IOTVUPIPlayer
object inside the onCreate
(). To create the UPI Player, the application has to invoke the method createPlayer(Context context, OTVUPISource source)
from the OTVUPIPlayerFactory
.
JAVA
OTVUPISource source = new OTVUPISource(STREAM_URI, "", "", "", null, null);
mIOTVUPIPlayer = OTVUPIPlayerFactory.createPlayer(this, source);
Preparing the listener
An OTVUPIEventListener
instance must be attached to the instance of IOTVUPIPlayer
with an IOTVUPIEventListener
implementation. This is done by invoking a method setEventListener
() on the IOTVUPIPlayer instance
and passing the OTVUPIEventListener
object to it. The application has to have its own implementation for the IOTVUPIEventListener
methods.
JAVA
mIOTVUPIPlayer.setEventListener(new UPIEventListener());
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);
}
}
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);
mIOTVUPIPlayer = OTVUPIPlayerFactory.createPlayer(this, source);
if (mIOTVUPIPlayer != null) {
mIOTVUPIPlayer.setEventListener(new UPIEventListener());
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();
}
}
}