0

I face a problem on audio encoder.I use MediaRecorder to record a voice. But, i find that my device must use default audioEncoder to record the voice successfully.

How can i check the type of default audio encoder??

Thanks.

Updated:

private MediaRecorder mRecorder = null;
public void startRecording(String aOutputFileName, int aOutputformat, int       aAudioEncoder) 
{
    if(null == mRecorder){
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(aOutputformat);
        mRecorder.setOutputFile(aOutputFileName);
        mRecorder.setAudioEncoder(aAudioEncoder);

        try {
            mRecorder.prepare();
            mRecorder.start();
        } 
        catch (IOException e) {
            e.printStackTrace();
            Log.e(LOG_TAG, "prepare() failed");
        }

    }
}

Call Function:

mVoiceRecorder.startRecording(mFileName, MediaRecorder.OutputFormat.THREE_GPP, MediaRecorder.AudioEncoder.DEFAULT);
King Wu
  • 387
  • 1
  • 8
  • 22
  • There's even the AudioCodec Type: DEFAULT Which should work under any circumstances. http://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder.html – sweisgerber.dev Aug 08 '12 at 06:58
  • Did you try using MediaRecorder.OutputFormat.DEFAULT & MediaRecorder.AudioEncoder.DEFAULT ; Encoder & Outputformat must be compatible. – sweisgerber.dev Aug 09 '12 at 10:58
  • i know it works. I just want to know the default encode. – King Wu Aug 10 '12 at 13:43

2 Answers2

0

You can specify the desired audiocodec via:

MediaRecorder.setAudioEncoder()

All Android devices support at least these codecs, so choose the one you wish.

sweisgerber.dev
  • 1,726
  • 17
  • 36
  • i try AMR_WB. But, my device cannot support it even though the version od android is 4.0.4 – King Wu Aug 07 '12 at 17:02
  • This sounds odd. Which device are you developing on? Some Logs of the errors you receive and sourcecode-snippets would help solving the problem. All I can say with your problem description is, Android supports all codecs listed here: http://developer.android.com/guide/appendix/media-formats.html If this isn't the case with your device, it's either some weird non-standard Android device, custom rom or special developer's edition.. But I bet there's something wrong woth the API usage. – sweisgerber.dev Aug 08 '12 at 06:49
  • My device is made by China Factory. There is no brand name. I cannot tell you the device information as i do not know too. You are right that my device is not a standard Android device. Is there no way to check the default encode? – King Wu Aug 08 '12 at 09:34
  • If http://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder.html#DEFAULT does not work I don't know how anything regarding recording should work. – sweisgerber.dev Aug 08 '12 at 09:50
  • Post sourcecode snippets and snippets from logcat if you need specific help. – sweisgerber.dev Aug 08 '12 at 09:51
  • i can verify this same issue on various devices in the wild. the only solution i've found is via reflection cycling through the AudioEncoder.class fields and testing each one for failure after trying both DEFAULT and AMR formats. Not all devices support these core formats no matter what the docs say – ThumbsDP Dec 23 '12 at 09:27
0

The issue is android is supposed to support certain codecs on all devices but that never happens. I've run into this issue, and posted a question here which gives you an idea of how i overcome it.

Every device should be able to use AudioEncoder.AMR_NB or AudioEncoder.DEFAULT but that is not the case. Your best bet IMO is to loop through the encoders available in the AudioEncoder class, and test if the codec fails on prepare() or start(). If it does, increment a counter and continue the loop. In my case i use an ErrorListener to catch errors or sucess and set the default encoder constant to shared settings.

Community
  • 1
  • 1
ThumbsDP
  • 543
  • 6
  • 18