Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to mute the "beep" by MediaRecorder.start()?

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 ?

like image 890
suitianshi Avatar asked Dec 16 '14 05:12

suitianshi


1 Answers

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);                                   }
        }
    }
}
like image 63
Shahed Avatar answered Nov 09 '22 05:11

Shahed