您好,我是iOS开发的新手,尝试编写一个基本应用程序。我希望有声音,更具体地说,从启动开始播放“sound.mp3”,因此我已将以下代码包含在我的程序中:
- (void)viewDidLoad
{
[super viewDidLoad];
[UIView animateWithDuration:1.5 animations:^{[self.view setBackgroundColor:[UIColor redColor]];}];
[UIView animateWithDuration:0.2 animations:^{title.alpha = 0.45;}];
//audio
NSString *path = [[NSBundle mainBundle]pathForResource:@"sound" ofType:@"mp3"];
AVAudioPlayer *theAudio = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
然而,这会导致模拟器和实体设备都没有声音播放。如果我能得到一些帮助将不胜感激。