I am facing the following issue.. I want to Record an audio file from Mic using AVAudioRecorder and stream the output to an AVAudioPlayer real time. I tried that by opening a stream
FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
where fileName is the name of the file that the recorder is writing. Then I tryed to initialize an AVAudioPlayer:
AVAudioPlayer player = AVAudioPlayer.FromData(NSData.FromStream(f));
That always returned a null player, so I wrapped the FileStream to a BufferedStream like
BufferedStream bf = new BufferedStream(f);
Then I initialized the player using the above line of code, but instead of passing the f stream I passed the bf stream.
That made the player at least to obtain a value other than null, bu开发者_如何学编程t I couldn't hear anything.
Is there any chance that someone has encountered the same problem, and knows the solution? Can I use AVAudioPlayer that way or am I doing all this the wrong way?
I know this is an older question, but I am answering in case someone else runs across the question.
To playback the just-recorded audio create the audio player from a URL that is based on the file name you just recorded to:
AVAudioPlayer player = AVAudioPlayer.FRomUrl(NSUrl.FromFileName(fileName));
player.PrepareToPlay();
player.Play();
Hopefully this helps someone.
精彩评论