需要关闭MediaRecorder播放状态改变时的声音 [英] Need to shut off the sound MediaRecorder plays when the state changes

查看:1167
本文介绍了需要关闭MediaRecorder播放状态改变时的声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在链路发现以下但无济于事的变化。

I have tried the changes found at the link below but with no avail.

<一个href=\"http://stackoverflow.com/questions/6804205/how-to-shut-off-the-sound-mediarecorder-plays-when-the-state-changes\">How状态发生变化时,关闭MediaRecorder播放声音

我都尝试

AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC,false);

// disable sound for recording.   
// 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);

但我仍然得到的声音时,我开始媒体记录器。我试图把这个code无论是在应用程序的启动和直接前:

But I still get the sound when I start the media recorder. I have tried putting this code both at the start of the app and directly before the:

mediaRecorder.start();

还有没有其他的建议?

Are there any other suggestions?

推荐答案

SetStreamMute仅用于系统和音乐。对于所有其他的你应该使用SetStreamVolume。

SetStreamMute works only for SYSTEM and MUSIC. For all the other you should use SetStreamVolume.

请尝试以下code:

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

有关完整性检查:

Log.d(TAG, String.format("%d,  %d, %d, %d, %d, %d, %d",
            audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM),
            audioManager.getStreamVolume(AudioManager.STREAM_MUSIC),
            audioManager.getStreamVolume(AudioManager.STREAM_ALARM),
            audioManager.getStreamVolume(AudioManager.STREAM_DTMF),
            audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION),
            audioManager.getStreamVolume(AudioManager.STREAM_RING)
            ));

结果应该得到:0,0,0,0,0,0

The result should give: 0, 0, 0, 0, 0, 0

请记住,使用量(不包括setStreamMute)游戏不会复位previous值活动死后,所以你可能要存储它们的onDestroy()来恢复或更早版本。

Keep in mind that the games with volume (exclude setStreamMute) won't reset the previous values after activity dies, so you probably want to store them to restore in onDestroy() or earlier.

这篇关于需要关闭MediaRecorder播放状态改变时的声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆