【发布时间】:2013-08-09 04:15:00
【问题描述】:
我使用一个代码来播放 .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] 文件://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf 2013-08-07 20:05:52.697 myApp [7006:907] 日志音频播放器:(空) 2013-08-07 20:05:52.701 myApp[7006:907] 未播放,错误:错误域 = NSOSStatusErrorDomain 代码 =-43“操作无法完成。(OSStatus 错误 -43。)” 2013-08-07 20:05:52.703 myApp[7006:907] 文件不存在
如您所见,音频播放器日志给出“null”,错误日志显示错误 -43.... 但我再说一遍...... iphone 4s 一切正常......
任何线索为什么会发生这种情况?他们是否对 iPhone 5 中的音频进行了一些更改?会不会是我的 iPhone 5 中的设置阻止了声音播放?任何帮助将不胜感激
【问题讨论】:
标签: iphone ios objective-c avaudioplayer