Android: Source Selection

In this topic, you will learn how the Brightcove Native Player SDK for Android uses a default source selection process when playing a video.

Introduction

When you retrieve videos from the Brightcove catalog, the SDK has to decide which source to play. This is implemented in the DefaultSourceSelectionController and ExoPlayerSourceSelectionController components.

Default selection process

The Brightcove Player SDK for Android uses a default source selection process. To simplify, we will focus on the SDK’s support for the Brightcove Playback API and Google’s ExoPlayer.

The default selection process is defined as follows:

  1. With the Brightcove Native SDK for Android 6.4+, HTTPS delivery for all source types is selected if available.

    Both the DefaultSourceSelectionController and ExoPlayerSourceSelectionController attempt to select the HTTPS version of the deliveryType selected. If no HTTPS source exists, the selection controller will select the first available.

  2. The BrightcoveExoPlayerVideoView looks for the first source that has a deliveryType of MPEG-DASH, and a profile that is neither urn:hbbtv nor urn:dvb. The SDK does not support playback with either of these DASH profiles, and so they will be filtered out of the sources.
  3. If the above is not found, source selection falls back to the first source with a deliveryType of HLS.
  4. If no such source is found, it falls back to the source with a deliveryType of MP4 and a bitrate closest to 256 kBps.

Once a source is found, the implementation continues as follows:

  1. If found, the selected source will be emitted with a response to the SELECT_SOURCE event.
  2. By default, the VideoPlaybackController handles the SELECT_SOURCE response, by emitting a SET_SOURCE event.
  3. The VideoDisplayComponent or a subclass handles the SET_SOURCE event by loading the URL into the underlying player (ExoPlayer).
  4. When playback begins, the underlying player is responsible for adapting the bitrate with HLS and DASH content. With HLS, the underlying player starts with the first bitrate listed in the master manifest.

When using the default transcode settings, the first HLS source should be the master m3u8 playlist that points to all of your individual sources (renditions).

Setting HLS sources

It is possible to customize source selection at the app level, to filter out any undesired delivery types before the SDK’s default source selection policy is invoked. To do this, you can modify the source collections that are set into the Video object from the Playback API's JSON response.

This example uses VideoUtil.filterSourcesOnDeliveryType to include only HLS sources:

catalog.findVideoByReferenceID(videoReferenceId, new com.brightcove.player.edge.VideoListener() {
	@Override
	public void onVideo(Video video) {
      VideoUtil.filterSourcesOnDeliveryType(video, DeliveryType.HLS);
      brightcoveVideoView.add(video);
      brightcoveVideoView.start();
	}
});