Skip to main content
Skip table of contents

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:

  • 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, 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 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.

JAVA
OTVPlaybackStatistics playbackStatistics = otvVideoView.getPlaybackStatistics();

Instantiate the OTVPlaybackStatisticsListener implementation, and attach it to the statistics object.

JAVA
        MyPlaybackStatisticsListener playbackStatsListener = new MyPlaybackStatisticsListener();
        playbackStatistics.setPlaybackListener(playbackStatsListener);
JavaScript errors detected

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

If this problem persists, please contact our support.