0

I need to play some audio through the earpiece. I am using AudioTrack to play some sound on a device. and the audio mode is set as STREAM_VOICE_CALL. Also, in my activity, the speakerphone is turned off by:

AudioManager am;            
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setSpeakerphoneOn(false);

This seems to work perfectly on 2.3 devices. But on 2.1, sound is still played from the speaker.

As a fix for this, I tried using setMode() as:

am.setMode(AudioManager.MODE_IN_CALL);

With this, the sound was played through the earpiece for 2.1 and 2.3, but most times not played at all by 2.3. Also, I read at some places that the setMode() should not be used by apps as it affects the system-wide phone state. here : http://code.google.com/p/sipdroid/issues/detail?id=270

Any help?

Alabhya
  • 490
  • 1
  • 9
  • 16

1 Answers1

0

Below 2.3, Android has been a little buggy with setSpeakerPhoneOn(). As per this answer, I think you'll need to use both API methods.

In regards to 2.3 audio not being played at all, check your in-call volume settings (which is what will be used). Try and keep track of the state the phone was in before using setMode() as well, perhaps setting it back to MODE_NORMAL once the audio manager is no longer being used.

Community
  • 1
  • 1
John Leehey
  • 22,052
  • 8
  • 61
  • 88
  • I did set it back to MODE_NORMAL. still the issue. I guess I'll have to live with the application being 2.3+ or buggy on 2.1. setmode() is not at all recommended for such applications (check the link in my question edit) – Alabhya Apr 19 '12 at 18:52
  • Because the routing methods are deprecated, I don't think there's any other solution, unless you use them specifically for 2.2-. It could be a bug with the phone you're using as well, btw, like an incomplete audio driver or something. – John Leehey Apr 19 '12 at 19:00