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

标签 iphone cocoa-touch audio ios core-audio

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

但是根据用户执行的一些操作,这个 mp3 应该停止/暂停一段时间,另一个 mp3 应该播放,然后这个 mp3 应该再次播放。

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

那么你们建议我应该做什么。 任何指针...?建议....?

最佳答案

正如我在这篇 post 中所写的那样, 你可以使用 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];

关于iphone - 在 iPhone 应用程序中播放连续声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014088/

相关文章:

iphone - NSThread vs. NSOperationQueue vs. ???在 iPhone 上

Javascript 方法 pause() 仅适用于音频元素

android - MediaRecorder 不将音频保存到文件

iphone - 使用 iOS5 的 XCode 编译现有的 Lua 应用程序

iphone - 删除重复的 nsmutableArray

ios - 如何在使用 iOS7 的 UINavigationBar 时以编程方式定位 UITableView?

ios - 在 iOS 8.1 中将整个应用程序的 View 旋转锁定为横向

iPhone: 'endInterruption' 没有被 <AVAudioSessionDelegate> 类调用

iOS 应用程序启动时间测量

objective-c - 仅当用户单击注释图钉时才调用方法的任何方法?