Question

Can I record more than one channel at the same time either using MediaRecorder or AudioRecord? What I want is to be able to record both MediaRecorder.AudioSource.VOICE_UPLINK and VOICE_DOWNLINK at the same time. Can be into two separate files or to same file with two channels. I tried using two separate instances of MediaRecorder. But only the first one records. The second one says the input is unavailable. I also tried to use one MediaRecorder and one AudioRecord at the same time. Again, Both works individually but when AudioRecord comes after MediaRecorder is started, The following errors are shown.

05-21 03:40:42.735: E/AudioRecord(1322): Could not get audio input for record source 1
05-21 03:40:42.735: E/AudioRecord-JNI(1322): Error creating AudioRecord instance:     initialization check failed.
05-21 03:40:42.825: E/AudioRecord-Java(1322): [ android.media.AudioRecord ] Error code -20     when initializing native AudioRecord object.

I also tried to put the second MediaRecorder on a new thread. Again the same result. So this makes me wonder if it is possible to record simultaneously at all. I was also thinking if i can use one AudioRecord with two channels set two separate inputs from VOICE_UPLINK and VOICE_DOWNLINK but I don't know how to set the sources if it is possible at all.

Thanks in advance

EDIT:

Lucifer's answer means AudioRecord cannot be called asynchronously having more than one instance running at the same time. Does anyone know a way in which AudioSource.VOICE_UPLINK and AudioSource.VOICE_DOWNLINK can be recorded at the same time? Maybe using a single instance of AudioRecord with multiple channels?

Was it helpful?

Solution

As per my Knowledge, AudioRecording is a Synchronized Method. So you can not use do two recording at a same time.

When your code is going for Second Recording Process it is showing the error 05-21 03:40:42.735: E/AudioRecord(1322): Could not get audio input for record source 1 which purely means that Recording Channel is already busy by First one.

However this can possible by parallel processing of two thread in such a ways that first thread record for the a specific amount of time. when control passes two second thread, first thread stops recording and second one start recording and vice versa. But as per mobile device this will become more complex. So better you record one channel at a time.

You can create a queue of recording, which will do recording one by one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top