如何静音"哔哔"通过MediaRecorder.start()?

时间:2014-12-16 05:27:06

标签: android mediarecorder android-audiomanager

我已尝试过以下链接中提到的所有方法

How to shut off the sound MediaRecorder plays when the state changes

Need to shut off the sound MediaRecorder plays when the state changes

但它们都不起作用。

任何人都知道如何实现这一目标?

1 个答案:

答案 0 :(得分:3)

虽然我来不及回答。它可能仍然有助于所有人都在搜索同样的问题。

在开始录音机之前添加以下两行代码.. 它会使手机静音...

//mute phone
 AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
 audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
 mediaRecorder.start();

启动录音机后等待一到两秒钟并取消静音,你可以使用以下可运行的...

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