Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Reliable Audio Recording, All Devices
    text
    copied!<p>Can someone please share with me a RELIABLE way to record audio across all devices using MediaRecorder? I'm simply trying to record a low-bitrate AMR format audio file, which according to google is standard across all devices. That's a bunch of crap. </p> <p>In my experience, there are many off-brand devices, tablets, etc. that will fail horribly when you use the default AudioEncoder.AMR_NB. My workaround is currently to use reflection to poll what encoders are in the superclass, then looping through each one with an errorlistener to see which one doesn't fail. Not only is this not graceful, but it doesn't catch all devices. I have also tried setting to default on the AudioEncoder and OutputFormat options (constant 0) and this fails horribly on some devices as well.</p> <p>Here is what i'm using if the default AMR encoder doesn't work:</p> <pre><code>Class encoderClass = MediaRecorder.AudioEncoder.class; Field[] encoders = encoderClass.getFields(); </code></pre> <p>Then i loop through each encoder, setting an error listener. If it ends successfully i set it as the default encoder as a setting. </p> <pre><code>for (int i = j; i &lt; encoders.length; i++) { try { int enc = encoders[i].getInt(null); recorder.reset(); recorder.setAudioSource(AudioSource.MIC); recorder.setOutputFormat(OutputFormat.THREE_GPP); recorder.setAudioEncoder(enc); //testing the encoder const here recorder.setOutputFile(amrPath); recorder.setMaxDuration(3000); recorder.setOnInfoListener(new OnInfoListener() { </code></pre> <p>I continue the loop if the listener catches an error:</p> <pre><code>if (arg1 == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { </code></pre> <p>This technique works for most devices. What about the rest? I still have devices that fall through the cracks and frankly i'd like something RELIABLE for nearly all devices????</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload