Raf*_*mos 11 media audio android record
我的Android应用程序在SurfaceHolder上使用MediaRecorder来显示相机捕获的实时预览.每次用户按下应用程序上的REC按钮,应用程序就会开始记录.每次MediaRecorder的状态切换到'start'时,Android会自动(?)发出蜂鸣声.这种哔哔声听起来与手机不同,这让我觉得这种哔哔声本身就与MediaRecorder的状态变化有关.如果手机的音量设置为静音,则不会发出蜂鸣声.
我谷歌并做了一些研究,但我找不到一种方法来关闭这个哔哔声.可能吗?如果是这样,怎么样?
该应用程序已经过测试:Nexus One 2.3.4,Desire HD 2.3.3
好的,接受的答案对我不起作用.在通过MediaRecorder录制时运行4.2.1(Jelly Bean)的Galaxy Nexus我需要使用AudioManager.STREAM_RING因为AudiManager.STREAM_SYSTEM不起作用.在每次录制开始时,它总是会发出"响声"声.
这是我使用"STREAM_RING"和其他人的解决方案.
// disable sound when recording.
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL,true);
// re-enable sound after recording.
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM,false);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF,false);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC,false);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING,false);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,false);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL,false);
Run Code Online (Sandbox Code Playgroud)
此外,文档状态确保在onPause()方法中重新启用音频.
我希望这有助于有人在这个问题上撕掉他们的头发.这会禁用所有声音流.您可以通过并找出您特别需要的那些.我发现不同版本的android在mediarecorder运行时使用不同的流来进行编钟.即,STREAM_RING适用于Android 4.2.1,但对于ICS,它不起作用.
编辑:正如我在下面提到的评论,我无法在三星Galaxy S1上禁用Android OS 2.3.3的声音.谁有运气呢?
Darrenp的解决方案有助于整理代码,但在我最近的手机更新(galaxy nexus android 4.3)中,音量/录音哔声再次启动!user1944526的解决方案绝对有帮助.努力让人们更容易理解......
使用类似的东西,
// class variables.
Integer oldStreamVolume;
AudioManager audioMgr;
enableSound() {
setMuteAll(false);
if (audioMgr != null && oldStreamVolume != null) {
audioMgr.setStreamVolume(AudioManager.STREAM_RING, oldStreamVolume, 0);
}
}
disableSound() {
audioMgr = (AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
oldStreamVolume = audioMgr.getStreamVolume(AudioManager.STREAM_RING);
audioMgr.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
为了完整性,您还可以在函数中调用darrenp的解决方案,或者包含上述所有STREAM_行.但对我来说,这些结合起来正在发挥作用.希望这有助于某人......
尝试
((AudioManager)context.getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,true);
Run Code Online (Sandbox Code Playgroud)
使所有声音静音。
| 归档时间: |
|
| 查看次数: |
10919 次 |
| 最近记录: |