我正在使用AVAudioPlayer创建一个iPhone应用程序。在iOS 6设备上它工作得很好。但是在iOS 5及更低版本中,它无法从iPod库中播放歌曲。当我尝试从NSBundle播放音乐文件时,它可以工作,所以问题只出现在我尝试从iPod库播放歌曲时。以下是我的代码,请检查:
if (isPlaying) {
[audioPlayer stop];
isPlaying = NO;
}
extern NSMutableArray *songsUrlArray;
extern int selectedSongIndex;
audioPlayer.volume = 1.0;
NSString *urlString = [NSString stringWithFormat:@"%@",[songsUrlArray objectAtIndex:selectedSongIndex]];
NSURL *url = [NSURL URLWithString:urlString];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
audioPlayer.delegate = self;
audioPlayer.numberOfLoops = 0;
if (audioPlayer == nil)
NSLog(@"%@",[error description]);
else{
[audioPlayer play];
isPlaying = YES;
}
编辑:
这是我得到的错误信息:
Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
当我使用谷歌搜索时,发现OSStatus error -43
出现在指定路径中没有可用内容的情况下。以下是3GS设备iPod库中歌曲的路径:ipod-library://item/item.mp3?id=564371652689620079
。但它无法播放。请帮忙解决。