Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing MediaRecorder bytes while recording in Xamarin Android
    text
    copied!<p>I would like to access the audio bytes that is being recorded by <code>MediaRecorder</code> during the recording process so I can send them with UdpClient to a server application.</p> <p>I'm able to do this with <code>AudioRecord</code> by doing the following (note the <code>while(true)</code> loop)</p> <pre><code> endRecording = false; isRecording = true; audioBuffer = new Byte[1024]; audioRecord = new AudioRecord ( // Hardware source of recording. AudioSource.Mic, // Frequency 11025, // Mono or stereo ChannelIn.Mono, // Audio encoding Android.Media.Encoding.Pcm16bit, // Length of the audio clip. audioBuffer.Length ); audioRecord.StartRecording (); while (true) { if (endRecording) { endRecording = false; break; } try { // Keep reading the buffer while there is audio input. int numBytes = await audioRecord.ReadAsync (audioBuffer, 0, audioBuffer.Length); //Send the audio data with the DataReceived event where it gets send over UdpClient in the Activity code byte[] encoded = audioBuffer; //TODO: encode audio data, for now just stick with regular PCM audio DataReceived(encoded); } catch (Exception ex) { Console.Out.WriteLine (ex.Message); break; } } audioRecord.Stop (); audioRecord.Release (); isRecording = false; </code></pre> <p>But I'm not sure how to get the bytes out of <code>MediaRecorder</code> so I can do something similar. Most of the examples I see only work with a file after the recording has been finished like the following example code from <a href="http://docs.xamarin.com/guides/android/application_fundamentals/working_with_audio" rel="nofollow">here</a> and <a href="http://developer.android.com/guide/topics/media/audio-capture.html" rel="nofollow">here</a>.</p> <p>I don't want to wait for a complete recording before it starts to send. I don't need <code>MediaRecorder</code> to record a file, just give me access to the bytes. But having the option to both write to a file and send the bytes would work well. Is there a way to do this, perhaps by using <code>ParcelFileDescriptor</code> or something else?</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