Monotouch:尝试播放使用 AVAudioPlayer 动态生成的文件中的音频
我面临以下问题.. 我想使用 AVAudioRecorder 从麦克风录制音频文件并将输出实时流式传输到 AVAudioPlayer。我尝试通过打开一个流
FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
其中 fileName 是记录器正在写入的文件的名称。然后我尝试初始化 AVAudioPlayer:
AVAudioPlayer 播放器 = AVAudioPlayer.FromData(NSData.FromStream(f));
它总是返回一个空播放器,所以我将 FileStream 包装到 BufferedStream 中,例如
BufferedStream bf = new BufferedStream(f);
然后我使用上面的代码行初始化播放器,但我没有传递 f 流,而是传递了 bf 流。
这使得玩家至少获得了除空以外的值,但我听不到任何声音。
有人遇到过同样的问题并且知道解决方案吗?我可以这样使用 AVAudioPlayer 还是我以错误的方式做这一切?
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, but 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这是一个较旧的问题,但我正在回答以防其他人遇到这个问题。
要播放刚刚录制的音频,请从基于您刚刚录制的文件名的 URL 创建音频播放器:
希望这对某人有帮助。
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:
Hopefully this helps someone.