Android。 6.0 中 AudioAttributes 的错误捕获存在 4 无效
Android. Error Invalid capture present 4 for AudioAttributes in 6.0
你好朋友,我正在开发来电录音机。在以下版本中成功录制音频(我在 samsung galaxy s3 中尝试过)但是当我在 6.0 版本中尝试时它给我错误 E/AudioAttributes: Invalid capture preset 4 for AudioAttributes.
我搜索了很多但没有找到确切的 answer.Is android 中有一个错误,当我用来记录 AudioSource.Voice_call 时给我错误。
提前致谢。如果有任何在 6.0 中记录来电的解决方案,请让我知道任何帮助,我们将不胜感激。
很久以后我得到了答案。这是由于制造商 issue.In 许多国家/地区的通话录音 banned.So 制造商不允许录制上行链路和下行链路。有一种方法可以打开麦克风并录制 it.It 最简单的方法。
你需要使用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;}
函数设置参数
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;}
任务音频设置参数
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);
}
}
你好朋友,我正在开发来电录音机。在以下版本中成功录制音频(我在 samsung galaxy s3 中尝试过)但是当我在 6.0 版本中尝试时它给我错误 E/AudioAttributes: Invalid capture preset 4 for AudioAttributes.
我搜索了很多但没有找到确切的 answer.Is android 中有一个错误,当我用来记录 AudioSource.Voice_call 时给我错误。
提前致谢。如果有任何在 6.0 中记录来电的解决方案,请让我知道任何帮助,我们将不胜感激。
很久以后我得到了答案。这是由于制造商 issue.In 许多国家/地区的通话录音 banned.So 制造商不允许录制上行链路和下行链路。有一种方法可以打开麦克风并录制 it.It 最简单的方法。
你需要使用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;}
函数设置参数
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;}
任务音频设置参数
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);
}
}