0

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?

Vinay S Shenoy
  • 4,028
  • 3
  • 31
  • 36

1 Answers1

0

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

Rupak
  • 3,674
  • 15
  • 23
  • That's fine. I already know how to do that. The thing is, I would prefer not to include my own music file to save space. I would prefer to programmatically play a tone instead. I've updated my question with another technique that i found but is still not working. – Vinay S Shenoy Apr 23 '12 at 10:26
  • In your updated code, you can merge the snippet used in http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1089414/How_To_-_Specify_Audio_Path_Routing.html?nodeid=1326675&vernum=0, i.e. iterate through all returned controls and check their type. If no Control is supported, a zero length array is returned (from API doc). – Rupak Apr 23 '12 at 11:20