我使用代码播放.caf音频文件,相同的代码在iPhone 4s和iPad 2中运行良好但在iPhone 5中根本不播放...

这是代码:

-(IBAction)checkSound:(id)sender

{

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Lunatic.caf", [[NSBundle mainBundle] resourcePath]]];

NSLog(@"%@",url);

NSError *error;

self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

self.audioPlayer.numberOfLoops = 0;

self.audioPlayer.volume = 1;

NSLog(@"log audioplayer: %@",audioPlayer);

if (audioPlayer != nil)

{

[self.audioPlayer prepareToPlay];

[self.audioPlayer play];

}

if (audioPlayer.playing == NO)

{

NSLog(@"not playing, error: %@",error);

}

if([[NSFileManager defaultManager] fileExistsAtPath:@"file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf"])

{

NSLog(@"file exist");

}

else

{

NSLog(@"file doesn't exist");

}

}

这是日志输出:

2013-08-07 20:05:52.694 myApp [7006:907] file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf 2013-08- 07 20:05:52.697 myApp [7006:907] log audioplayer:(null)2013-08-07 20:05:52.701 myApp [7006:907]没有播放,错误:错误Domain = NSOSStatusErrorDomain Code = -43“操作无法完成 . (OSStatus错误-43 . )“2013-08-07 20:05:52.703 myApp [7006:907]文件不存在

你可以看到audioplayer日志给出“null”,错误日志说错误-43 ....但我重复...用iphone 4s一切正常....

任何线索为什么会发生这种情况?他们在iPhone 5中用音频改变了什么吗?可能是我的iPhone 5中的一个设置阻止声音播放?任何帮助将不胜感激

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐