Skip to main content
Skip table of contents

Player statistics

Refer to the example code for (5.33.x) 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:

  • OTVNetworkStatistics is used in conjunction with the OTVNetworkStatisticsListener interface to provide information on selected and available bitrates, network usage, current content server, etc.

  • OTVPlaybackStatistics is used in conjunction with the OTVPlaybackStatisticsListener interface to provide information on resolution, buffered duration, stream bit rate, playback speed, etc.

  • OTVRenderingStatistics provides 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.

JAVA
 OTVPlaybackStatistics playbackStatistics = otvVideoView.getPlaybackStatistics();

Call the methods which are of interest.

JAVA
        int streamBitrate = playbackStatistics.getStreamBitrate();
        long bufferedDuration = getBufferedDuration();

Listening for statistics events

Implement the appropriate listener interface.

JAVA
        private class MyPlaybackStatisticsListener implements OTVPlaybackStatisticsListener {
            private static final String TAG = "MyPlaybackStatisticsListener";

            @Override
            public void streamBitrateChanged(int xNewBitrate) {
                 OTVLog.i(TAG, "Stream bit rate changed to: " + xNewBitrate);
            }

            @Override
            public void resolutionChanged(int xNewWidth, int xNewHeight) {
                OTVLog.i(TAG, "Resolution changed to: " + xNewWidth + " * " + xNewHeight);
            }

            @Override
            public void playbackSpeedChanged(float xPlaybackSpeed) {
                OTVLog.i(TAG, "Playback speed changed to: " + xPlaybackSpeed);
            }
        }

Obtain the relevant statistics object from an OTVVideoView instance.

JAVA
OTVPlaybackStatistics playbackStatistics = otvVideoView.getPlaybackStatistics();

Instantiate the OTVPlaybackStatisticsListener implementation, and register it with the statistics object.

JAVA
        MyPlaybackStatisticsListener playbackStatsListener = new MyPlaybackStatisticsListener();
        playbackStatistics.addPlaybackListener(playbackStatsListener);

The httpProcessingError method will be triggered in OTVNetworkStatisticsListener when an HTTP request error happens. All error details can be obtained using methods of HTTPProcessing

JAVA
        private class MyNetworkStatisticsListener implements OTVNetworkStatisticsListener {
            private static final String TAG = "MyNetworkStatisticsListener";
			......
            
            @Override            
            public void httpProcessingEnded(HTTPProcessing xHttpProcessing) {
			}
            
			@Override
            public void httpProcessingError(iHTTPProcessing xHttpProcessing) {
				// Get error details from httpProcessing.	
  				// The range provide the time window during which this activity occurred.
  				Timerange timeRange = xHttpProcessing.getRange();
    		    // The url is the uniform resource locator access via HTTP.
  				String sourceUrl = xHttpProcessing.getUrl();
   				// The HTTP status code returned by the server
  				Integer errorStatus = xHttpProcessing.etStatus();
   				// The MIME type of the resource returned by the server
  				String mimeType = xHttpProcessing.getMimetype();
   			    // The response size transferred in bytes
			    int responseLength = xHttpProcessing.getResponse();
			    // The response part contains information specific to the response
  				byte[] response = xHttpProcessing.getResponseBody()                              }
        }
JavaScript errors detected

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

If this problem persists, please contact our support.