This example portal displays information about the audio tracks which are present in the current stream. Streams may contain many audio tracks, for different languages, and with different encodings and sample rates. This example works best with a stream containing more than one audio track.
The setup for the video window, and the initialization of the Media Player is the same as in the TV Portal example, so make sure you have understood that first.
mediaPlayer.addEventListener(mediaPlayer.ON_DATA_AVAILABLE, onDataAvailable);
A new event listener, ON_DATA_AVAILABLE, is used in this example. When the media player completes its opening of a stream, and actually starts receiving the video data, then it raises this event. It can take a second or two from the mediaPlayer.play() call, so it needs to be handled asynchronously with an event.
The event handler, onDataAvailable, receives an event argument. The status of this event lets the portal know if the data has begun to flow, or if it has stopped. If the data has become available, then the portal updates the audio stream info.
function onDataAvailable(event) {
dataAvailable = event.status;
if (event.status == true ) {
updateAudioStreamInfo();
}
}
Once the data is available, the media player instance can return information about the current stream through the getStreamInfo() and getAudioStreamInfo() functions. The information returned iss in the form of a data structure which holds a number of stream components (audio tracks, video tracks, subtitle information, teletext, etc). The ordering of these components is not known, so the portal iterates through the array, checking to see which of the components are audio ones.
var streamInfo = mediaPlayer.getStreamInfo();
var clist = streamInfo.availableComponents;
// count the number of audio tracks
var x;
numAudioTracks = 0;
for (x=0; x < clist.length; x++) {
if (clist[x].type == mediaPlayer.COMPONENT_AUDIO) {
numAudioTracks++;
}
}
When information on a particular component is required, the getAudioStreamInfo() or getVideoStreamInfo() media player functions are used, and the appropriate component passed as an argument.
The portal keeps track of one of the available audio tracks, which is the track selected by the user. This is stored in the currAudioChan variable. The audio tracks are numbered 1 to x. By iterating through clist and counting the objects of type COMPONENT_AUDIO, the portal finds the audio track selected by the user. Then it requests the detailed information with the getAudioStreamInfo() function:
audioStreamInfo = mediaPlayer.getAudioStreamInfo(clist[x]);
This function returns a structure of information for the chosen component. See the documentation for the ToiMediaPlayerBaseAudioStreamInfo structure for more details on the structures members.
Lastly, the members of the struct are read, and the DOM searched and updated with the values.