同时在Android中使用的麦克风在多个应用程序 [英] Use microphone in multiple app simultaneously in Android

查看:7799
本文介绍了同时在Android中使用的麦克风在多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Android设备上,我们想使用麦克风在同时2应用程序。

We have an Android device on which we would like to use the microphone in 2 app simultaneously.

事实上,我们有一个在后台运行的语音命令服务(我们使用的是 CMU狮身人面像库)。的问题是,当我们开始视频记录(摄像机应用),我们不能启动记录,即2的应用程序不能同时访问到麦克风

In fact, we have a vocal command service that is running in the background (we are using the CMU Sphinx library). The problem is when we start a video recorder (camera application), we can't start the recording as 2 applications can't access to the microphone at the same time.

错误

08-20 12:20:14.601: I/MediaRecorderJNI(7261): prepare: surface=0x59590668
08-20 12:20:15.916: E/MediaRecorder(7261): start failed: -38
08-20 12:20:15.916: E/com.example.CamcorderView(7261): Failed to start recorder.
08-20 12:20:15.916: E/com.example.CamcorderView(7261): java.lang.IllegalStateException
08-20 12:20:15.916: E/com.example.CamcorderView(7261):     at android.media.MediaRecorder.start(Native Method)

请注意,相机工作良好,当声带服务处于关闭状态。

Note that the camera works well when the vocal service is off.

此外,我precise,我已经阅读过了这个主题:

Moreover, I precise that I've already read this thread :

<一个href="http://stackoverflow.com/questions/4669047/android-accessing-the-microphone-simultaniously-recognizerintent-own-app">Android:同时放访问麦克风(RecognizerIntent +自己的应用程序)

但这里不同的是,我们有一个手的O / S和内核上。因此,我们如果需要的话可以申请补丁。

but the difference here is that we have a hand on the O/S and the kernel. So we can apply patch if needed.

它是一个 SDK / OS /内核限制?有没有什么解决办法?

Is it an SDK/OS/Kernel limitation? Is there any workaround ?

推荐答案

这种情况发生

例如

当你想要录制的电话。 你可以使用开源的通话记录。 看到和的这个

when you want to record phone call. you can use the open source call recorder. see this and this

下面是一个code样品

Here is a code sample

private MediaRecorder recorder = null;
public void onCreate()
{
    super.onCreate();
    recorder = new MediaRecorder();
    Log.i("CallRecorder", "onCreate created MediaRecorder object");
}

public void onStart(Intent intent, int startId) {

    if (isRecording) return;

    Context c = getApplicationContext();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);

    Boolean shouldRecord = prefs.getBoolean(Preferences.PREF_RECORD_CALLS, false);
    if (!shouldRecord) {
        Log.i("CallRecord", "RecordService::onStartCommand with PREF_RECORD_CALLS false, not recording");
        return;
    }

    int audiosource = Integer.parseInt(prefs.getString(Preferences.PREF_AUDIO_SOURCE, "1"));
    int audioformat = Integer.parseInt(prefs.getString(Preferences.PREF_AUDIO_FORMAT, "1"));

    recording = makeOutputFile(prefs);
    if (recording == null) {
        recorder = null;
        return; //return 0;
    }

    Log.i("CallRecorder", "RecordService will config MediaRecorder with audiosource: " + audiosource + " audioformat: " + audioformat);
    try {
        // These calls will throw exceptions unless you set the 
        // android.permission.RECORD_AUDIO permission for your app
        recorder.reset();
        recorder.setAudioSource(audiosource);
        recorder.setOutputFormat(audioformat);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recorder.setOutputFile(recording.getAbsolutePath());
        //recorder.setMaxDuration(msDuration); //1000); // 1 seconds
        //recorder.setMaxFileSize(bytesMax); //1024*1024); // 1KB

        recorder.setOnInfoListener(this);
        recorder.setOnErrorListener(this);

        try {
            recorder.prepare();
        } catch (java.io.IOException e) {
            Log.e("CallRecorder", "RecordService::onStart() IOException attempting recorder.prepare()\n");
            t.show();
            recorder = null;
            return;
        }
        Log.d("CallRecorder", "recorder.prepare() returned");

        recorder.start();
        isRecording = true;
        Log.i("CallRecorder", "recorder.start() returned");
        updateNotification(true);
    } catch (java.lang.Exception e) {
        Log.e("CallRecorder", "RecordService::onStart caught unexpected exception", e);
        recorder = null;
    }

    return;
}

这篇关于同时在Android中使用的麦克风在多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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