2

以下のリンクにある変更を試しましたが、役に立ちませんでした。

状態が変化したときに 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);

しかし、メディアレコーダーを起動すると、まだ音が聞こえます。このコードをアプリの開始時と次の直前の両方に配置しようとしました。

mediaRecorder.start();

他の提案はありますか?

4

1 に答える 1

2

SetStreamMute は、SYSTEM および MUSIC に対してのみ機能します。他のすべてについては、SetStreamVolume を使用する必要があります。

次のコードを試してください。

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

ボリュームのあるゲーム (setStreamMute を除く) は、アクティビティが終了した後に以前の値をリセットしないことに注意してください。

于 2013-12-17T20:00:03.690 に答える