Search code examples
androidrecordgalaxymediarecorder

Couldn't record with Samsung Galaxy S2 but could record with other phones from mic


However my app couldn't record in Samsung Galaxy S 2 from mic, it has been recording in other phones from mic.

Recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
Recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
Recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

In my code, I select the source type from 0 to 4, select the encoder type as amr-nb, amr-wb, aac or default, select the output format type as .3gp, .mp4 or .amr and also select audio channel as 1 or 2. I try all of combinations which are up. At least one of the combinations work in many phones. But none of them could work in Samsung Galaxy S 2. It records the file and the duration of the record is true but the voice is only silence!

In my research in web with this problem, i find that it could be derived from the microphone type. Although in my code I select the audio source type as default, mic, voice downlink, voice uplink, voice call, it couldn't work. Then I set the audio source type as hard by that 0, 1, 2, 3, 4 instead of MediaRecorder.AudioSource.MIC etc. But it also couldn't work...


Solution

  • I've had issues on the S2 where an app will lock up the microphone and won't release it, especially if you are doing quick development cycles where you lock and release the mic just as you uninstall the app (and re-install a new version). Sometimes it unlocks after some time has passed, but the sure way to make sure the mic is available is to restart the phone after a failed attempt.

    I've been able to record audio using the following settings in the AudioRecord object:

    int buffer_size = 2 * AudioRecord.getMinBufferSize(16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
    recorder = new AudioRecord(
      MediaRecorder.AudioSource.MIC,               //audio source
      16000,                                       //16kHz sample rate
      AudioFormat.CHANNEL_IN_MONO,                 //channel
      AudioFormat.ENCODING_PCM_16BIT,              //encoding
      buffer_size );                               //buffer size