Android Programmatically set AudioEncoder for MediaRecorder

2

My question is: How can I programmatically set the AudioEncoder for MediaRecorder?

I am trying to programmatically set the AudioEncoder by replacing the statically set AAC or AAC_ELD with the int variable mEncode which is manually selected from a list of variables such as:

int mEncode = 3; OR int mEncode = 5;

When I replace AAC with int variable mEncode with value of 3 or 5 the code will not compile. I get error message Cannot resolve symbol 'mEncode".

Android documentation shows that: int AAC Constant Value: 3 (0x00000003) int AAC_ELD Constant Value: 5 (0x00000005) https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder.html

Can anyone help me with the correct code?

Java code:

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSamplingRate(16000);
    mRecorder.setAudioEncodingBitRate(24000);
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

    // my current static method set with AAC or AAC_ELD:
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mRecorder.setOutputFile(mFileName);

    // my dynamic method set with int variable mEncode:
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.mEncode);
java
android
android-mediarecorder
asked on Stack Overflow Apr 24, 2017 by user2308699

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0