我已经尝试了几个选项(其中许多选项在SO和其他地方从post引用)以在iPhone模拟器上播放音乐,但到目前为止还没有一个有效。我试过了 -
<AVFoundation/AVFoundation.h>
并将AVFoundation.framework
添加到我的链接框架中。我在viewDidLoad
中有以下代码播放文件gundam.mp3
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"gundam" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1;
player.volume = 0.9;
NSLog(@"The sound URL is %@", soundFileURL);
[player play];
NSLog似乎能够正确捕获文件:The sound URL is file://localhost/Users/zallanx/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/[...]/Missile%20Defender.app/gundam.mp3
根据我尝试的所有选项,我不确定我做错了什么,并感谢您的帮助。谢谢!