0

我想在 android 6.0 上捕获视频,并且还希望它在捕获视频时不会录制音频。我试图以编程方式使麦克风静音,但它不适用于 Android 6.0 及更高版本。有人请分享您解决此问题的经验,任何类型的帮助将不胜感激!我用下面的代码来静音麦克风

AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.ADJUST_MUTE);
        if (audioManager.isMicrophoneMute() == false) {
            audioManager.setMicrophoneMute(true);
        } else {
            audioManager.setMicrophoneMute(false);
        }

并使用意图打开相机

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);

        // set video quality
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        intent.putExtra(MediaStore.MEDIA_SCANNER_VOLUME, 0);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file

        // start the video capture Intent
        startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
4

2 回答 2

0

它可以在调用模式时提供帮助

 AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
            audioManager.setMode(AudioManager.MODE_NORMAL);
            if(state) //state-boolean
            {
               audioManager.setMicrophoneMute(false);
               audioManager.setMode(AudioManager.MODE_IN_CALL);
               state = false;
            }
            else
            {
              audioManager.setMicrophoneMute(true);
              state = true;
            }
于 2017-12-02T11:12:35.700 回答
0

尝试这个

private void setMicMuted(boolean state){
AudioManager myAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);

// get the working mode and keep it
int workingAudioMode = myAudioManager.getMode();

myAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

// change mic state only if needed
if (myAudioManager.isMicrophoneMute() != state) {
    myAudioManager.setMicrophoneMute(state);
}

// set back the original working mode
myAudioManager.setMode(workingAudioMode);

}

于 2017-12-02T11:19:56.207 回答