Player statistics
Refer to the example code for Resolution capping when implementing this functionality. Although this only uses OTVPlaybackStatistics, the same procedure applies to the other statistics classes.
The CONNECT Player SDK provides classes and interfaces enabling you to access statistics concerning the player and the current stream:
OTVNetworkStatisticsis used in conjunction with theOTVNetworkStatisticsListenerinterface to provide information on selected and available bitrates, network usage, current content server, etc.OTVPlaybackStatisticsis used in conjunction with theOTVPlaybackStatisticsListenerinterface to provide information on resolution, buffered duration, stream bit rate, etc.OTVRenderingStatisticsprovides information on frame rate (nominal and actual) and frame drops (per second and total).
Player statistics are provided via two mechanisms:
- Directly calling methods on the statistics objects to query state; for example, current bitrate.
- Implementing the provided listener interfaces, which provide callback methods for certain events that offer some information about that event, for example, change of resolution, and attaching these listeners to their appropriate statistics objects.
OTVNetworkStatistics and OTVPlaybackStatistics provide information using both of these mechanisms. OTVRenderingStatistics only contains methods for querying player information directly.
Example code
Querying player state directly
Obtain the relevant statistics object from an OTVVideoView instance.
OTVPlaybackStatistics playbackStatistics = otvVideoView.getPlaybackStatistics();
Call the methods which are of interest.
int streamBitrate = playbackStatistics.getStreamBitrate();
long bufferedDuration = getBufferedDuration();
Listening for statistics events
Implement the appropriate listener interface.
private class MyPlaybackStatisticsListener implements OTVPlaybackStatisticsListener {
private static final String TAG = "MyPlaybackStatisticsListener";
@Override
public void streamBitrateChanged(int newBitrate) {
OTVLog.i(TAG, "Stream bit rate changed to: " + newBitrate);
}
@Override
public void resolutionChanged(int newWidth, int newHeight) {
OTVLog.i(TAG, "Resolution changed to: " + newWidth + " * " + newHeight);
}
}
Obtain the relevant statistics object from an OTVVideoView instance.
OTVPlaybackStatistics playbackStatistics = otvVideoView.getPlaybackStatistics();
Instantiate the OTVPlaybackStatisticsListener implementation, and attach it to the statistics object.
MyPlaybackStatisticsListener playbackStatsListener = new MyPlaybackStatisticsListener();
playbackStatistics.setPlaybackListener(playbackStatsListener);