Question

Anyone know how to play audio track in ear piece or ear speaker of the device??

I have used this:

AudioManager audio_service = (AudioManager) getSystemService 
(Context.AUDIO_SERVICE); 
                // set the mode in call, so that the sound can come from earpiece 
                audio_service.setSpeakerphoneOn(false); 
                audio_service.setMode(AudioManager.MODE_IN_CALL); 
                audio_service.setRouting(AudioManager.MODE_NORMAL, 
                                AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); 
mediaplayer.start();

but nothing happened..:| Can anyone tel me?

Was it helpful?

Solution

Just got it to work on 2.2. I still needed the In_Call setup which I don't really like but I'll deal with it for now. I was able to ditch the call routing stuff which is deprecated now. I found you defenitly need the Modfiy_Audio_Settings permission, no error without it but it the setSpeackerPhone method just does nothing. Here is the mock up of the code I used.

private AudioManager m_amAudioManager;  
m_amAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);  
m_amAudioManager.setMode(AudioManager.MODE_IN_CALL); 
m_amAudioManager.setSpeakerphoneOn(false); 

Curtsy : Android - Getting audio to play through earpiece

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top