我已经尝试了以下链接中提到的所有方法
How to shut off the sound MediaRecorder plays when the state changes
Need to shut off the sound MediaRecorder plays when the state changes
但它们都不起作用.
谁知道如何实现这一目标?
解决方法
虽然我来不及回答它.它仍然可以帮助所有人都在谷歌搜索同样的问题.
在开始媒体记录器之前添加以下两行代码..
它会静音手机声音..
//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); } } } }