MediaRecorder and AudioRecord Problems, 2.1

All your problems with Audio, Video and Images.

MediaRecorder and AudioRecord Problems, 2.1

Postby ChezJfrey » Wed Jun 23, 2010 3:18 am

I've seen evidence of this particular problem on the web, but can't seem to locate the reasons or a solution.

I continue to get errors and force closes trying two seemingly simple methods to record audio on the Android.

First, using MediaRecord:

MediaRecorder mRecorder = new MediaRecorder();
Log.d("com.mydevice.RecordAudio: ", " try to setAudioSource");
mRecorder.setAudioSource(MediaRecorder.AudioSource .MIC);
catch(IllegalStateException e){
//Never get here
Log.d("com.mydevice.RecordAudio: ", " parm set error");
//Never get here either
Log.d("com.mydevice.RecordAudio: ", " successfully setAudioSource");

The above results in the following logcat output:

D/com.mydevice.RecordAudio: ( 1623): try to setAudioSource
E/audio_input( 1104): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value
E/audio_input( 1104): VerifyAndSetParameter failed
D/AndroidRuntime( 1623): Shutting down VM
W/dalvikvm( 1623): threadid=3: thread exiting with uncaught exception (group=0x4001b198)
E/AndroidRuntime( 1623): Uncaught handler: thread main exiting due to uncaught exception

Second method, using AudioRecord:

Log.d("com.mydevice.RecordAudio: ", " try to initialize AudioSource");
AudioRecord mRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 16384);
Log.d(TAG, " recordStart");
try {
} catch (IOException e) {
Log.d(TAG, " recordStart IOException");

This results in the following:

D/com.mydevice.RecordAudio: ( 1637): try to initialize AudioSource
D/AudioHardwareMot( 1095): Codec sampling rate already 8000
D/Registration Create( 1637): recordStart
D/Registration Create( 1637): recordStart IOException

From the documentation, I understand that these methods won't necessarily work in the emulator (though I did enable audio and camera in my VMs, just in case), and some people on the 'net indicated that even with emulator errors, a physical phone worked. But, running the two methods above on my phone results in the same errors indicated in the emulator logcat output, with the same force closes.

I am using the SDK revision 5, and tried Android 1.5 (just to try) and 2.1 emulators. I made sure the following was in my manifest:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

I loaded it onto my Motorola Droid 2.1, with Cyanogen and still the errors.

Does anyone have any idea how, or if I can resolve this? I feel like an idiot since it seems so simple...
Posts: 2
Joined: Wed Jun 23, 2010 3:10 am


Re: MediaRecorder and AudioRecord Problems, 2.1

Postby ChezJfrey » Thu Jun 24, 2010 1:04 am

LOL! Turns out I was being an idiot.

The unsupported parameter message when calling setOutputFormat, was actually not the problem that was causing the force close. Rather, it was the call to setOutputFile. I found this after laboriously adding log messages after every single call.

I tried both local and external storage and using a string and FileDescriptor and nothing was working. Every time I called that method, I got a force close or caught an error in a try/catch. I finally found an example that was sending the correct context. Since I had separated this process from the UI, what I needed to to was instantiate my class with the application context like so:


and within the MyRecordClass constructor, MyRecordClass(Context context):

this.context = context;

Even though calls to FileOutputStream and getFD() actually still created an empty file without the proper context, the MediaRecorder was obviously crashing and must be due to some sort of context disconnect. Apparently, by adding the above, and now in what I'm guessing is the proper context and even though I still encounter that unsupported parameter error in the logcat, the app continues on without a hitch and I get a valid recording. Joy!

I have now successfully called this process in another thread and even sending .finish() to the UI activity, the recording continues until it's finished (specified by duration). So, there it is...onward.
Posts: 2
Joined: Wed Jun 23, 2010 3:10 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests