Android通话录音未录制来电语音

Bha*_*mar 22 android native phone-call android-ndk android-mediarecorder

我正在使用自动呼叫记录器应用程序,我能够在android 6下面使用记录语音呼叫MediaRecorder.AudioSource.VOICE_CALL,从android 6无法使用VOICE_CALL记录语音呼叫.我设法录音使用,MediaRecorder.AudioSource.MIC但这里传入的声音没有被记录,我想在正常模式下录制语音通话,而不是在扬声器模式下.请帮帮我.(我曾尝试过Xiomi Redmi 4a(机器人6),没有工作).

 myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
 myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
 myRecorder.setMaxDuration(60 * 60 * 1000);
 AudioManager audiomanager =
 (AudioManager)getSystemService(AUDIO_SERVICE);
 audiomanager.setMode(2);
Run Code Online (Sandbox Code Playgroud)

编辑:权限没有问题.

更新:任何人都知道如何强制另一个流到MIC音频源.这需要原生的android代码.请帮我解决此 问题.有关路由音频的详细信息,请参阅此问题

Vik*_*rev 11

你需要使用ndk.以下是需要完成的功能示例.

加载libmedia.so和libutils.so

int load(JNIEnv *env, jobject thiz) {
    void *handleLibMedia;
    void *handleLibUtils;
    int result = -1;
    lspr func = NULL;

    pthread_t newthread = (pthread_t) thiz;

    handleLibMedia = dlopen("libmedia.so", RTLD_NOW | RTLD_GLOBAL);
    if (handleLibMedia != NULL) {
        func = dlsym(handleLibMedia, "_ZN7android11AudioSystem13setParametersEiRKNS_7String8E");
        if (func != NULL) {
            result = 0;
        }
        audioSetParameters = (lasp) func;
    } else {
        result = -1;
    }

    handleLibUtils = dlopen("libutils.so", RTLD_NOW | RTLD_GLOBAL);
    if (handleLibUtils != NULL) {
        fstr = dlsym(handleLibUtils, "_ZN7android7String8C2EPKc");
        if (fstr == NULL) {
            result = -1;
        }
    } else {
        result = -1;
    }

    cmd = CM_D;

    int resultTh = pthread_create(&newthread, NULL, taskAudioSetParam, NULL);

    return result;}
Run Code Online (Sandbox Code Playgroud)

函数setParameters

int setParam(jint i, jint as) {
pthread_mutex_lock(&mt);

audioSession = (int) (as + 1);

kvp = "input_source=4";
kvps = toString8(kvp);

cmd = (int) i;

pthread_cond_signal(&cnd);
pthread_mutex_unlock(&mt);

return 0;}
Run Code Online (Sandbox Code Playgroud)

任务AudioSetParameters

void *taskAudioSetParam(void *threadid) {
    while (1) {
        pthread_mutex_lock(&mt);
        if (cmd == CM_D) {
            pthread_cond_wait(&cnd, &mt);
        } else if (audioSetParameters != NULL) {
             audioSetParameters(audioSession, kvps);
        }
        pthread_mutex_unlock(&mt);
    }
}
Run Code Online (Sandbox Code Playgroud)

有一个库和一个使用示例https://github.com/ViktorDegtyarev/CallRecLib