Monotouch:尝试播放使用 AVAudioPlayer 动态生成的文件中的音频

发布于 2024-11-04 03:05:24 字数 667 浏览 1 评论 0原文

我面临以下问题.. 我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-11-11 03:05:24

我知道这是一个较旧的问题,但我正在回答以防其他人遇到这个问题。

要播放刚刚录制的音频,请从基于您刚刚录制的文件名的 URL 创建音频播放器:

AVAudioPlayer player = AVAudioPlayer.FRomUrl(NSUrl.FromFileName(fileName));
player.PrepareToPlay();
player.Play();

希望这对某人有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文