我有一个 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/