Search code examples
javablackberryblackberry-jdemultimedia

How can I play Alert.startAudio() through the phone speaker?


I need to play Alert.startAudio() through the loudspeaker of a Blackberry device instead of the headset.

I know that I can change the Audio path through the AudioPathControl interface, but I don't know how to get an instance of AudioPathControl.

I found a LINK on how to do it on the Blackberry Knowledge base, but it only tells me how to do it using the Player class, which I don't want to do. Is there any way to get an instance of AudioPathControl of the current Application?

I would prefer to play a tone programmatically instead of including my own sound file. I found the following code snippet for that.

Player p = javax.microedition.media.Manager.createPlayer(javax.microedition.media.Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl tc = (ToneControl) p.getControl("ToneControl");
AudioPathControl apc = (AudioPathControl) p
.getControl("AudioPathControl");
apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
tc.setSequence(mySequence);
p.start();

But the problem is that apc is null and throws an Exception. Any solution?


Solution

  • Check the section Where Does the Sound Go? (preview from Google Books), from Advanced BlackBerry 6 Development By Chris King.