PlayBook QNX AudioManager Example

Posted on January 24, 2011 | 3 comments

I wanted to show how to use another QNX AIR API, specifically the class AudioManager. It provides a singleton instance of the AudioManager which gives access to the available inputs and outputs on the device. You can then set the levels and mute state of both input and output. In the example code project QNXAudioManager it plays a local mp3 that is bundled with the application. It also displays the different event messages that are fired while making changes to the input or output. And it provides a QNX VolumeSlider to set the output level while playing the mp3.

Here is the main chunk of code that setups and uses the singleton instance of AudioManager.

audioManager = AudioManager.audioManager;
log("AvailableInputs: " + audioManager.availableInputs.length);
for (var i:int = 0; i < audioManager.availableInputs.length; i++)
    log(i + " - " + audioManager.availableInputs[i]);  
log("AvailableOutputs: " + audioManager.availableOutputs.length);  
for (var j:int = 0; j < audioManager.availableOutputs.length; j++)
    log(j + " - " + audioManager.availableOutputs[j])
audioManager.addEventListener(AudioManagerEvent.AVAILABLE_INPUTS_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.AVAILABLE_OUTPUTS_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.CONNECTED_INPUT_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.CONNECTED_OUTPUT_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.INPUT_LEVEL_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.INPUT_MUTE_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.OUTPUT_LEVEL_CHANGED, eventHandler);
audioManager.addEventListener(AudioManagerEvent.OUTPUT_MUTE_CHANGED, eventHandler);
log("connectedInput: " + audioManager.connectedInput);
log("connectedInput: " + audioManager.connectedOutput);

There is only seems to be one input for the PlayBook; found at qnx.system.AudioInput.INPUT. But there are four different audio output types: qnx.system.AudioOutput.BLUETOOTH, qnx.system.AudioOutput.HDMI, qnx.system.AudioOutput.HEADPHONES, and qnx.system.AudioOutput.SPEAKERS. You can check the audioManager.connectedInput and audioManager.connectedOutput values against the constants above.

Then the slider changes the output level on slider_move event:

protected function slider_slider_moveHandler(event:SliderEvent):void

Here is what the app looks like on the simulator, nothing fancy but a way to check out the event firing off the AudioManager instance.

QNX AudioManager Example App

All the source code for this example is on github here.