我使用播放.caf音頻文件的代碼,相同的代碼在iPhone 4s和iPad 2中運行良好,但在iPhone 5中完全不能播放。 。音頻文件不會在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] not playing, error: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)" 2013-08-07 20:05:52.703 myApp[7006:907] file doesn't exist
正如你可以看到audioplayer日誌給「空」和錯誤日誌說錯誤-43 .... 但我重複...與iPhone 4s一切正常......
任何線索爲什麼會發生這種情況?他們在iPhone 5中改變了音頻嗎?它可能是我的iPhone 5中阻止聲音播放的設置嗎?任何幫助將不勝感激
我tryed添加[audioPlayer prepareToPlay]在打電話給audioplayer播放之前......但沒有任何反應......我還添加了一張支票以查看audioplayer是否正在播放,並表示它不是...我更新了問題以向您顯示新代碼... – Blue
好吧檢查我的新編輯。聽起來像你的路徑是搞砸了 –
我更新了代碼...仍然沒有工作,但現在有一些錯誤...檢查問題中的代碼... – Blue