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

那年仲夏 提交于 2019-12-10 03:36:35

问题


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 ?


回答1:


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);                                   }
        }
    }
}


来源:https://stackoverflow.com/questions/27498092/how-to-mute-the-beep-by-mediarecorder-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!