I have tried all methods mentioned in the following links
How to shut off the sound MediaRecorder plays when the state changes
Need to shut off the sound MediaRecorder plays when the state changes
but none of them work.
Anyone knows how to achieve that ?
Though I am too late to answer it. It may still help peoples who all are googling the same problem.
Before starting media recorder add following two lines of code .. Its gonna mute phones sound..
//mute phone
AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
mediaRecorder.start();
After starting media recorder wait one or two seconds and un-mute the phone, u may use following runnable...
new Thread(new UnmuterThread()).start();
//timer thread to un-mute phone after 1 sec
//This is runnable inner class inside your activity/service
class UnmuterThread implements Runnable{
@Override
public void run() {
synchronized (this){
try {
wait(1000);
} catch (InterruptedException e) {
} finally {
//unmute the phone
AudioManager audioManager1 = (AudioManager) context.getSystemService(AUDIO_SERVICE);
audioManager1.setRingerMode(AudioManager.RINGER_MODE_NORMAL); }
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With