Player statistics

You are recommended to refer to the example code for resolution capping when implementing this functionality. Although this uses only OTVPlaybackStatistics, the same procedure is applicable for the others statistics classes.

The OpenTV Player SDK provides a number of classes and interfaces allowing the integrator to access statistics concerning the player, and the current stream:

  • OTVNetworkStatistics - information on bit rates (selected and available), network usage, current content server, etc.
    • OTVNetworkStatisticsListener - interface used in conjunction with OTVNetworkStatistics
  • OTVPlaybackStatistics - information on resolution, buffered duration, stream bit rate, etc.
    • OTVPlaybackStatisticsListener - interface used in conjunction OTVPlaybackStatistics
  • OTVRenderingStatistics - 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, e.g. current bit rate
  • Implementing the provided listener interfaces, which provide callback methods for certain events that offer some information about that event - e.g. 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 ResolutionListener implements OTVPlaybackStatisticsListener {
            @Override
            public void streamBitrateChanged(int newBitrate) {
                // ignore bit rate changes
            }
    
            @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:

        ResolutionListener resListener = new ResolutionListener();
        playbackStatistics.setPlaybackListener(resListener);