在 iPhone 应用程序中播放连续声音

发布于 2024-09-28 18:21:51 字数 253 浏览 0 评论 0原文

我有一个 iPhone 应用程序,它要求我在应用程序的整个生命周期内播放循环的 mp3 声音。

但根据用户执行的一些操作,该 mp3 应该停止/暂停 while &另一个 mp3 应该播放 &那么这个 mp3 应该会再次恢复播放。

我还没有在 iPhone 上真正使用过任何音频 API,我只是使用 AudioToolbox 在按钮点击时播放声音,仅此而已。

那么你们建议我应该做什么。 有什么指点吗...?建议......?

I have an iPhone application which requires me to play a looping mp3 sound during the entire lifetime of app.

But based on some actions performed by user this mp3 should stop/pause for while & another mp3 should play & then this mp3 should resume playing again.

I havent really used any audio API on iPhone yet, I've just used AudioToolbox for playing sounds on button taps thats all.

So what do you guys recommend I should do.
Any pointers...? suggestions....?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

若相惜即相离 2024-10-05 18:21:51

正如我在这篇文章中所写的,您可以使用 AVAudioPlayer

代码摘录:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL URLForString:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL];
player.numberOfLoops = -1; //infinite

[player play];

您可以通过以下方式暂停它:

[player pause];

just as I wrote in this post, you can use AVAudioPlayer

code extract:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL URLForString:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL];
player.numberOfLoops = -1; //infinite

[player play];

and you can pause it with:

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