Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVAudioPlayer升级到Xcode5后在游戏中崩溃_Ios_Objective C_Xcode5_Avaudioplayer - Fatal编程技术网

Ios AVAudioPlayer升级到Xcode5后在游戏中崩溃

Ios AVAudioPlayer升级到Xcode5后在游戏中崩溃,ios,objective-c,xcode5,avaudioplayer,Ios,Objective C,Xcode5,Avaudioplayer,请注意下面Stephen的绝妙提示:AVAudioPlayer在正常工作时会抛出异常;很可能根本没有撞车 我有这么奇怪的问题。将我的项目升级到Xcode5后,应用程序在声音播放或prepareToPlay时崩溃 NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"]; AVAudioPlayer *snd = [[AVAudioPlayer alloc] initWithContentsOfU

请注意下面Stephen的绝妙提示:AVAudioPlayer在正常工作时会抛出异常;很可能根本没有撞车


我有这么奇怪的问题。将我的项目升级到Xcode5后,应用程序在声音播放或prepareToPlay时崩溃

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"];
AVAudioPlayer *snd = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

NSLog(@"sound = nil? %d",snd == nil); // 0
NSLog(@"file = %@",snd.url.filePathURL.lastPathComponent); //test.mp3
NSLog(@"duration %f",snd.duration); //96.213333
在上述行之后:
1) snd不是零-没关系
2) snd.url.filePathURL.lastPathComponent返回正确的文件名(test.mp3),-没关系
3) 持续时间是96.21333-没关系

因此对象存在并加载了声音(持续时间正常)

那我会的

[snd play]
它崩溃了

如果我这样做

[snd prepareToPlay]
它也崩溃了:(


有人知道它为什么会崩溃吗?

试试这段代码。它正在工作,我已经在代码中使用过了 它已经在Xcode 5上进行了测试,可以正常工作:

NSURL* url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp3"];
NSAssert(url, @"URL is valid.");
NSError* error = nil;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
if(!audioPlayer)
{
    NSLog(@"Error creating player: %@", error);
}
else
{ 
    [audioPlayer play];
}

在Xcode的输出日志/控制台中是否打印出任何类型的崩溃信息?只有一些汇编程序linesI从Xcode3升级,我不使用ARCenable异常断点查看更多详细信息。但请注意,播放音频会导致断点被命中,这会使应用程序停止4次,但不会崩溃(只是看起来是这样)谢谢!!!!:)我很笨;)我刚刚在这个项目中添加了“AddExceptionsBreakpoint”,正如您所说,它只是停止了4次。所以代码一切正常。只是我需要记住,即使代码中没有错误,声音也会导致异常。它仍然会崩溃:(如果我打开新的Xcode项目,我的代码工作正常。它在从Xcode 3迁移的项目上不工作。问题是我添加了“异常断点”对于项目和播放声音,即使没有错误,它也会被调用4次。我以为它会崩溃,但不是崩溃,而是停止了4次。谢谢大家的帮助。