Skip to main contentIBM Video Streaming Developers

Changing Tracks

Video streams can contain multiple tracks of different types (usually video, audio and text such as for captions). The Player SDK lets you control which of these tracks are selected and presented to the user. See this document’s MediaTrackChangeListener section or the corresponding javadoc for API reference.

Usage

  • Set a MediaTrackChangeListener on an initialized player, call attach() when appropriate.
  • When the player determines the available track groups it will report it through the listener’s void onMediaTracksChanged(MediaTrackGroupHolder mediaTrackGroups) callback.
  • The mediaTrackGroups object holds the available media tracks for each track type. Use these to instruct the player’s specific renderers to play a certain media track. A renderer can also be disabled.

Example: Selecting a subtitle / closed captions track

PlayerFactory playerFactory = new PlayerFactory(API_KEY, activity);
ContentDescriptor contentDescriptor = new ContentDescriptor(ContentType.RECORDED, 123456L);
Player player = playerFactory.createPlayer(contentDescriptor.toString());
player.initWithContent(contentDescriptor);
player.setMediaTracksChangeListener(mediaTrackChangeListener);
player.attach();
//... Inside the MediaTrackChangeListener
public void onMediaTracksChanged(MediaTrackGroupHolder mediaTrackGroups) {

Example: Querying whether a MediaFormat is supported

//... Inside the MediaTrackChangeListener
public void onMediaTracksChanged(MediaTrackGroupHolder mediaTrackGroups) {
for (MediaTrack videoTrack : mediaTrackGroups.videoTracks) {
for (MediaFormat videoFormat : videoTrack.mediaFormats) {
if (mediaTrackGroups.formatSupportInfo.isSupported(videoFormat)) {
logSupportedFormat(videoTrack, videoFormat);
} else {
logUnsupportedFormat(videoTrack, videoFormat);
}

For more detailed and general examples please consult the provided sample app.