Skip to main content
Skip table of contents

Resolution capping

To test this feature and view the example code, please see the Android SDK 4 Example Code Quick Start guide.

You can configure the OpenTV Player for Android SDK to limit the maximum resolution that the user will experience during playback. The feature works in a very similar way to bitrate capping, in that HLS layers above the selected threshold will be dismissed and ignored by the adaptation algorithms.

It is not mandatory for HLS streams to describe their layers' resolutions; in such a case the cap is not applied.
If the resolution cap is set lower than the resolution of the lowest rendition, then that lowest rendition will be played.
Any Output Control limitations will take precedence over any user-defined resolution cap that is applied.
Applying or removing the limit during playback will take effect after the buffered duration has been consumed.

Example code

NMPVideoView  has a public API that lets you configure this feature by specifying the width and height (in pixels) at which the cap will be applied:

JAVA
public void setMaxResolution(int width, int height)

The special values of zero for width and height will remove any resolution limit; these are the default values.

These settings are persisted for the lifecycle of the player, and so they apply to every stream played once they are set.

To implement a listener detecting resolution changes (optional), you need to set up an IPlaybackStatisticsListener listener and implement the resolutionChanged() method:

JAVA
  private class ResolutionListener implements IPlaybackStatisticsListener {
    @Override
    public void streamBitrateChanged() {
      // We are not interested in bitrate for this example
    }

    @Override
    public void resolutionChanged() {
      // The callback does not contain the resolution, but it can be retrieved fom the PlaybackStatistics class
      Pair<Integer, Integer> resolution = PlaybackStatistics.getResolution();
      Integer width = resolution.first;
      Integer height = resolution.second;
      mResolutionMonitor.setText(String.format(Locale.ENGLISH, "%d x %d", width, height));
    }
  }

The listener uses the PlaybackStatistics class, which is not a static class, but all of its members actually are.

The listener with the implemented callback above should then be instantiated and assigned to a PlaybackStatistics class with a static callback, but only after the onPrepared() event, when statistics are available:

JAVA
    mNMPVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mp) {
        mp.start();
        PlaybackStatistics.setPlaybackListener(new ResolutionListener());
      }
    });
JavaScript errors detected

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

If this problem persists, please contact our support.