• Quick Start
  • Booting
  • Platform
  • Portals
  • References
    • API Reference TOI3
    • IIP Reference
  • Resources
ARRIS Enterprises, Inc. Confidential Information

Audio Tracks

Introduction

As streams can contain several different audio tracks (to support different languages and choice of formats), a mechanism exists for querying the current stream for the available audio tracks, as well as for receiving notifications when the list of available tracks changes.

Receiving notifications

When changing channels, or even when changing from one TV program to another within the same channel, the availability of languages may change. The KreaTV platform uses the ToiMediaPlayerBase::ON_STREAM_INFO_CHANGED event identifier to inform the portal application that an audio track has become available, become unavailable, or has been selected according to the CFG_MEDIA_AUDIO_LANGUAGEPRIORITY list. The first thing the portal needs to do is to subscribe to the ON_STREAM_INFO_CHANGED event identifier:

<sdk_root>/examples/example-html-portal/modules/settings/settings.js

mediaPlayer.addEventListener(
  toi.consts.ToiMediaPlayerBase.ON_STREAM_INFO_CHANGED,
  this.onStreamInfoChanged);

When this event is triggered, the portals handleStreamInfoChanged function will be called, and passed a ToiMediaPlayerStreamInfoChangedEvent. It contains three (possibly empty) arrays, indicating the available, active (the currently selected) and the changed components.

The event handler

<sdk_root>/examples/example-html-portal/modules/settings/settings.js

onStreamInfoChanged: function(event) {
  var componentEntry = null;

  for (var i = 0; i < event.availableComponents.length; i++) {
    componentEntry = event.availableComponents[i];
      switch (componentEntry.type) {
      case toi.consts.ToiMediaPlayerBase.COMPONENT_AUDIO:
        ...
        break;
      case toi.consts.ToiMediaPlayerBase.COMPONENT_SUBTITLE:
        ...
        break;
      }
    }
  }

event.availableComponents is an array of ToiComponentEntry , which contain an id and type for each component that is available. Remember that video tracks and subtitle information may also be available, so the type is used to differenciate between them. To detect the available audio/languages, the portal looks for the COMPONENT_AUDIO types. It's now possible to request more detailed information for the component from the media player:

<sdk_root>/examples/example-html-portal/modules/settings/settings.js

streamInfo = mediaPlayer.getAudioStreamInfo(component);
language = streamInfo.language;

The call to ToiMediaPlayerBase::getAudioStreamInfo() returns a ToiAudioStreamInfo object, which contains a language string (a three-character code as specified by ISO 639 part 2, among other things.

Language Autoselection

When the configuration object CFG_MEDIA_AUDIO_AUTOSELECTION is set to true, the KreaTV platform automatically selects the audio track based on a priority-sorted list of preferred languages, set in CFG_MEDIA_AUDIO_LANGUAGEPRIORITY. The example.config boot image configuration sets default values for these:

<sdk_root>/build_scripts/example.config

# Set priority for automatic selection of language track
# The configuration objects here work in a similar way to the
# subtitle autoselection
kreatv-option-is-default::cfg.media.audio.autoselection=true
kreatv-option-is-default::cfg.media.audio.languagepriority="eng,swe,dan"
kreatv-option-is-default::cfg.media.audio.formatpriority="eac3,ac3,aac,mpeg"
kreatv-option-is-default::cfg.media.audio.priorityorder="language,format"

Note that it is possible to also select based on certain audio formats, and to prioritize between selection based on language or format. See the documentation for the individual configuration objects for more details.

Making a selection

Since CFG_MEDIA_AUDIO_AUTOSELECTION is set to true, the KreaTV platform selects the available component whose language field best matches CFG_MEDIA_AUDIO_LANGUAGEPRIORITY, and starts it playing. The component becomes active. The event handler also checks event.activeComponents to see when this occurs, and to update the UI with the currently selected language.

To force a selection of another language, for example "eng", the value of CFG_MEDIA_AUDIO_LANGUAGEPRIORITY is examined. The portal moves or prefixes "eng" to the front of the list (giving it the highest priority. The code for doing this is located in the setLanguagePriorityList() function. Once the configuration object value changes, the autoselection mechanism in the KreaTV platform notices and runs its selection algorithm again, switching audio tracks.

The above is still using autoselection mechanism though. If you really want to force a specific language, then you should disable the autoselection by setting CFG_MEDIA_AUDIO_AUTOSELECTION to FALSE and then call ToiMediaPlayer::activateComponent() to activate a particular component.

Updating the UI

When a new language is selected by KreaTV (based on a change to the available languages in the stream, or a change to the CFG_MEDIA_AUDIO_LANGUAGEPRIORITY list resulting in a different best match, then the matching component is activated. In the handleStreamInfoChanged event handler, the portal scans the event.activeComponents for one of type COMPONENT_AUDIO to find out what the currently selected audio track is. The infobar module in the portal is also subscribed to this event as it too displays the active audio language.

5.1.p5

Copyright (c) 2017 ARRIS Enterprises, LLC. All Rights Reserved. ARRIS Enterprises, LLC. Confidential Information.