Search code examples
androidxamarin.androidaudio-recording

Android AudioRecord StartRecording - Application Hang


I have been trying to get my Android App to use the mic and start recording. But the app just keeps crashingon the AudioRecord StartRecording() method.

_recorder = new AudioRecord(AudioSource.Mic, RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, _bufferSize);

        if (_recorder.State == State.Initialized)
            _recorder.StartRecording();  // <-- HANGS ON THIS LINE

Please help. Do I need to place StartRecording in a thread or something?

I am using Xamarin Android, with code based on http://www.edumobile.org/android/audio-recording-in-wav-format-in-android-programming/


Solution

  • to answer my question - with clues from Vyshak (THANKS). It appears that StartRecording should really be called in a separate thread (which makes me wonder why a lot of sample codes do not do this).

    A good reference point for anyone doing this in the future will be this sample code right here: https://developer.xamarin.com/samples/monodroid/Example_WorkingWithAudio/