强制MediaRecorder使用内部麦克风 [英] Forcing MediaRecorder to use internal microphone

查看:1303
本文介绍了强制MediaRecorder使用内部麦克风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这样的事情开始录音:

I'm using something like this to initiate audio recording:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/dev/null");
recorder.prepare();
recorder.start();

我想总是从内置麦克风录音。使用上面的code,音源切换到外接麦克风只要一插上。我看过了的文档并不能找到一个方法来设置preferred麦克风。

I want to always record from the internal microphone. Using the code above, the audio source switches to the external microphone as soon as one is plugged in. I've looked over the docs and can't find a way to set a preferred mic.

推荐答案

不幸的是,你试图去对抗Android的音频管理,这是,系统选择取决于所选择的音频源和输入设备时耳机pluged在,输入,对MIC的音频源,被切换到耳机。您可以确认此检查的logcat的AudioPolicyManager的相关消息。

Unfortunately, you're trying to go against Android's audio management, this is, the system selects input device depending on selected audio source and, when the headset is pluged in, input, for MIC audio source, is switched to the headset. You can confirm this checking logcat's AudioPolicyManager's related messages.

我的建议是用不同的音源播放欺骗系统。我会建议使用<一个href="https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html#CAMCORDER"相对=nofollow>摄像机,或者至少尝试VOICE_RECOGNITION或VOICE_COMMUNICATION。

My suggestion would be playing with different audio sources to trick the system. I would recommend using CAMCORDER or, at least, try VOICE_RECOGNITION or VOICE_COMMUNICATION.

主要问题与摄录机是,它可以通过使用多媒体麦克风,这就是,一个在装置的背面。更具体,我建议按照以下步骤:

Main problem with CAMCORDER is that it can be using multimedia microphone, this is, the one at the back of the device. More in detail, I would suggest following procedure:

  1. 收听 ACTION_HEADSET_PLUG 的意向。
  2. 当您收到的意图,尝试切换音源摄像机。
  3. 摄像机的音频源的选择取决于有效的相机,所以你可以尝试通过MediaREcorder的<一个强制前置摄像头使用(和,然后,前内置麦克风) href="http://developer.android.com/reference/android/media/MediaRecorder.html#setCamera%28android.hardware.Camera%29"相对=nofollow> setCamera
  1. Listen for ACTION_HEADSET_PLUG Intent.
  2. When you receive the intent, try to switch audio source to CAMCORDER.
  3. CAMCORDER audio source is selected depending on active camera so you can try to force front camera usage (and, then, front internal mic) through MediaREcorder's setCamera

希望这有助于

这篇关于强制MediaRecorder使用内部麦克风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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