我已尝试过以下链接中提到的所有方法
如何在状态改变时关闭 MediaRecorder 播放的声音 https://stackoverflow.com/questions/6804205/how-to-shut-off-the-sound-mediarecorder-plays-when-the-state-changes
需要在状态改变时关闭MediaRecorder播放的声音 https://stackoverflow.com/questions/14369445/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); }
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)