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:
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
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:
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:
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.