我正在使用AVAudioPlayer創建iPhone應用程序。它在iOs 6設備中工作正常。但它不是從iOs 5及更低版本的iPod庫播放歌曲。當我試圖播放來自NSBundle的音樂文件時,它正在工作,所以只有當我嘗試播放iPod庫中的歌曲時纔會出現問題。這裏是我的代碼,請AVAudioplayer不從iOS中的iPod庫播放歌曲5
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.)"
當我用Google搜索,我發現OSStatus error -43
是當到達那裏在指定的路徑中沒有可用的內容。以下是3GS設備中iPod庫的歌曲路徑,ipod-library://item/item.mp3?id=564371652689620079
。但它沒有演奏。請一些 請幫
請檢查該鏈接,它可以幫助你 http://stackoverflow.com/questions/1605846/avaudioplayer-with-external-url-to-m4p – Anand
我不是想打歌從一個url,我想從ipod庫播放歌曲。 – Mithuzz
@Mithuzz你有沒有想過這個?我得到確切同樣的錯誤,試圖從庫中播放的歌曲。只發生在ios5上。 – soleil