Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
lmeylan
Posts: 8
Registered: ‎05-21-2010
My Device: Blackberry bold
My Carrier: swisscom
Accepted Solution

setting audio path to handset does not work even if no exception is raised

Hi all, 

 

I am reading a stream of UDP data and then play it to the phone. Ideally, the sound should go to the internal speaker as in the case of phone calls. But what I hear is always from the external speaker even f I set the audio path to be handset. No exception is raised, no error. 

 

Anyone had the same problem? Is there a workaround? 

 

See my code below and the comments. 

 

Thanks for your help

 

------------------------------------------------------------------------------

 

// create my own stream data source

 

playerStreamDataSource = new PlayerStreamDataSource("audio/amr");

 

try  {

  player = Manager.createPlayer(playerStreamDataSource); 

  player.addPlayerListener(this);

 

  player.setLoopCount(1);

  player.realize();  

 

} catch (Exception e) { 

  System.out.println("ERROR : " + e);

 

// now get the control and set audiopath

Control[] controls = player.getControls();

 

for (int i = controls.length - 1; i >= 0; i--)  {

  if (controls[i] instanceof AudioPathControl) {

    audioPathControl = (AudioPathControl) controls[i];

    try {

        audioPathControl.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSET);

        // THIS DOES NOT RAISE EXCEPTION BUT

        // I STILL HEAR SOUND THROUTH EXTERNAL LOUDSPEAKER AFTERWARDS

    catch (Exception e) {

        System.out.println("ERROR :" + e.toString());

    }

    audioPathControl.getAudioPath(); 

    //  IF I PRINT THIS, IT GIVES ME AUDIO_PATH_HANDSET,

    // EVEN THOUGH IT IS NOT WHAT I HEAR

  } else if (controls[i] instanceof VolumeControl) {

    volumeControl = (VolumeControl) controls[i];

    try {

        volumeControl.setLevel(50);

        // THIS WORKS

    }

    catch (Exception e)  {

        System.out.println("ERROR : " + e.toString());

    } 

  }

}

Please use plain text.
Administrator
MSohm
Posts: 14,434
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: setting audio path to handset does not work even if no exception is raised

What BlackBerry Smartphone model and BlackBerry device software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: setting audio path to handset does not work even if no exception is raised

Is any application by any chance recording audio at the same time?

Please use plain text.
Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: setting audio path to handset does not work even if no exception is raised

That's simply writing what you are playing on the speaker to a file.

 

Hope you are not talking about recording a phone call.

Please use plain text.
Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: setting audio path to handset does not work even if no exception is raised

 


lmeylan wrote:

Hi all, 

 

I am reading a stream of UDP data and then play it to the phone. Ideally, the sound should go to the internal speaker as in the case of phone calls. But what I hear is always from the external speaker even f I set the audio path to be handset. No exception is raised, no error. 

 

Anyone had the same problem? Is there a workaround? 

 

See my code below and the comments. 

 

Thanks for your help

 

------------------------------------------------------------------------------


I don't think there is a difference between the two as I have tried this on the 8520, 8530, 8900, 9000, 9700.  I have resolved to use volume controls. Low volume for handset and 100% volume for speaker.

 

Please use plain text.
New Contributor
lmeylan
Posts: 8
Registered: ‎05-21-2010
My Device: Blackberry bold
My Carrier: swisscom

Re: setting audio path to handset does not work even if no exception is raised

I have 2 blackberry Bold 9700, one has v5.0.0.656 (Bundle 1111, Platform 5.1.0.153) the other has version 5.0.0.423 (Platform 5.1.0.116).

 

To answer the other questions:

--

I have an open UDP connection for streaming, which fills a buffer that I pass to the player for playing out (using sourcestream and datasource interface). 

 

There is another application at the same time, that is recording from the microphone (using a player and a recordControl). Would that influence the "setaudiopath" ?

 

Thanks

 

Please use plain text.
New Contributor
lmeylan
Posts: 8
Registered: ‎05-21-2010
My Device: Blackberry bold
My Carrier: swisscom

Re: setting audio path to handset does not work even if no exception is raised

>> I don't think there is a difference between the two as I have tried this on the 8520, 8530, 8900, 9000, 9700.  I have resolved to use volume controls. Low volume for handset and 100% volume for speaker.

 

I did manage to have sound only coming from the internal speaker when trying playing simple tone.So it should work.

 

What puzzles me is that when I use my streaming player (and yes, there is another thread at the same time doing some unrelated recosrding with another player), I get no error nor exception when setting the audio path to the internal speaker (HEADSET) but the sound is still coming from the external speaker (HANDSFREE).

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: setting audio path to handset does not work even if no exception is raised

[ Edited ]

There is definitely a noticeable difference between the earpiece and the loudspeaker audio path. If I recall correctly, setting the volume to 100 in earpiece mode does not at all give you the loudness you get when you active the loudspeaker and set the volume to 100.

 

Try toggling the speakerphone using AudioPathControl.toggleSpeakerphone().

 

P.S. If there is another Player recording audio at the same time, you have to use that Player's AudioPathControl instead of your Player's one.

Please use plain text.
New Contributor
lmeylan
Posts: 8
Registered: ‎05-21-2010
My Device: Blackberry bold
My Carrier: swisscom

Re: setting audio path to handset does not work even if no exception is raised

>>P.S. If there is another Player recording audio at the same time, you have to use that Player's AudioPathControl instead of your Player's one.

 

This solved my problem. It seems that both player needs to have the right audiopath set even though only one of them is playing sound.

 

 

Please use plain text.