Android中實現對內置聲源的錄製有兩種方案java
AudioSource輸入源
android
public final class AudioSource {
private AudioSource() {}
/** Default audio source **/
public static final int DEFAULT = 0;
/** Microphone audio source */
public static final int MIC = 1;
/** Voice call uplink (Tx) audio source */
public static final int VOICE_UPLINK = 2;
/** Voice call downlink (Rx) audio source */
public static final int VOICE_DOWNLINK = 3;
/** Voice call uplink + downlink audio source */
public static final int VOICE_CALL = 4;
/** Microphone audio source with same orientation as camera if available, the main
* device microphone otherwise */
public static final int CAMCORDER = 5;
public static final int VOICE_RECOGNITION = 6;
public static final int VOICE_COMMUNICATION = 7;
public static final int REMOTE_SUBMIX = 8;
}
複製代碼
REMOTE_SUBMIX能夠實現內錄功能,有兩點比較麻煩:
git
(1)須要系統權限 github
(2)會截走揚聲器和耳機的聲音,也就是說再錄音時本地沒法播放聲音
bash
https://github.com/aosp-mirror/platform_build/tree/master/target/product/security
網絡
用signapk.jar對應用進行簽名
app
java -jar signapk.jar platform.x509.pem platform.pk8 app-unsigned.apk signed.apk
複製代碼
signapk獲取地址:
ui
https://github.com/techexpertize/SignApkspa
https://github.com/maks/aosp-signapk
.net
修改framework下av/services/audiopolicy/AudioPolicyManager.cpp
if (mAvailableOutputDevices.getDevice(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, String8("0")) != 0) {
device2 = availableOutputDeviceTypes & AUDIO_DEVICE_OUT_REMOTE_SUBMIX;
}
複製代碼
修改成:
if (mAvailableOutputDevices.getDevice(AUDIO_DEVICE_OUT_REMOTE_SUBMIX, String8("0")) != 0) {
device2 = availableOutputDeviceTypes & AUDIO_DEVICE_OUT_REMOTE_SUBMIX;
device2 |= (availableOutputDeviceTypes & AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
device2 |= (availableOutputDeviceTypes & AUDIO_DEVICE_OUT_SPEAKER);
}複製代碼
如今就能夠使用MediaRecorder.AudioSource.REMOTE_SUBMIX實現內錄功能了。
該方案只適用於知道系統簽名或者本身編譯系統源碼的狀況
參考文章:
https://www.jianshu.com/p/916ede1d1f48 https://blog.csdn.net/liuhaitao_share/article/details/41249175 https://blog.csdn.net/jinzhuojun/article/details/33748031
第二種方法來自開源項目:
https://github.com/iwo/SCR-Screen-Recorder-app