【发布时间】:2015-09-12 19:36:45
【问题描述】:
我一直在使用以下代码在 sprite kit 游戏中播放背景音乐,它在 Xcode 6.4 中运行良好,但现在抛出异常并导致游戏崩溃:
- (void)startBackgroundMusic
{
NSError *err;
NSURL *file = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"lostinspace.caf" ofType:nil]];
_backgroundAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:&err];
if (err) {
NSLog(@"error in audio play %@",[err userInfo]);
return;
}
[_backgroundAudioPlayer prepareToPlay];
_backgroundAudioPlayer.numberOfLoops = -1;
[_backgroundAudioPlayer setVolume:0.5];
[_backgroundAudioPlayer play];
}
在 didMoveToView 中将上述代码声明为 :[self startBackgroundMusic];
我查看了文档,但无法找出我已经拥有的内容有什么问题。有谁知道如何解决这个问题?以下是建议:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** -[NSURL initFileURLWithPath:]: nil string parameter”
【问题讨论】:
标签: objective-c sprite-kit avplayer ios9 xcode7