0

I want to play an audio file let's say from the loudspeakers and by the use of a button change it to built-in loudspeakers and vice versa. A built-in loudspeaker could be a headset, a bluetooth device. But let's consider for simplicity the built-in loudspeakers.

I'm doing the following thing:

  1. Initialise the player with appropriate context and uri and then

    asyncPlayer.play(context, uri, true, st);

where st I have seen it takes the values STREAM_VOICE_CALL, STREAM_MUSIC, STREAM_RING, STREAM_NOTIFICATION

I have noticed that when I use the

audioManager.setSpeakerphoneOn(true/false);

This works only when the st value is STREAM_VOICE_CALL. For STREAM_RING I could do the same only my changing the mode, i.e.

audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

To be honest I find it a little bit counter-intuitive as I would expect that with any file I would be able to set the Speakerphone on and off without changing the mode...

Could you give me some indications on how it works, or any other suggestions?

The reason I'm using the asyncPlayer is because I want to do at the same time other things as well.

Thanks

Simon Bosley
  • 1,114
  • 3
  • 18
  • 41
Symeon Mattes
  • 1,169
  • 16
  • 40
  • `setSpeakerphoneOn`, as the name implies, should be used for toggling speaker phone mode on/off. It's not intended as a mechanism for changing the routing of arbitrary streams (e.g. music streams). – Michael May 19 '16 at 13:18
  • Yes...but if I have for instance STREAM_RING then why it doesn't change the speaker phone mode on/off? – Symeon Mattes May 19 '16 at 13:43
  • What I would like to have is a mechanism in which I could turn the speaker phone mode on/off for any sound I play – Symeon Mattes May 19 '16 at 13:44
  • Well, again, it's set**Speakerphone**On, not setLoudspeakerOn. The purpose of the function is if you've got a voice call and want to switch between the default call routing and using the loudspeaker + farfield mic. That's really the only use-case the function is intended for. – Michael May 19 '16 at 13:55
  • There are some hackish ways for re-routing music streams. See e.g. http://stackoverflow.com/questions/12036221/how-to-turn-speaker-on-off-programatically-in-android-4-0/12037719#12037719 But I'm not aware anything that's officially supported. Things might've changed since I stopped working with audio-related Android stuff though. – Michael May 19 '16 at 13:59

0 Answers0