我在尝试播放歌曲文件(通过MPMediaPickerController选择)时收到上述错误。在iOS6中工作正常,但在iOS5上我收到错误。这是代码:
DLog(@"song: %@", self.customSongUrl); //always logs a valid url such as ipod-library://item/item.mp3?id=-1890948386979134309
if (self.customSongUrl) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSError *error = nil;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.customSongUrl error:&error];
if (!self.audioPlayer)
{
NSLog(@"AVAudioPlayer could not be established: %@", error); //results in Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
}
[self.audioPlayer prepareToPlay];
[self.audioPlayer setNumberOfLoops:-1];
[self.audioPlayer play];
});
}
根据我所做的研究,错误-43表示该文件不存在。但是该文件是从带有MPMediaPickerController的iTunes库中选择的。而且,这个错误只发生在iOS5上。那么为什么iOS5会认为这首歌不存在?
作为参考,这就是我从媒体选择器获取歌曲网址的方式:
- (void)mediaPicker:(MPMediaPickerController *) mediaPicker didPickMediaItems:(MPMediaItemCollection *) collection
{
MPMediaItem *item = [[collection items] objectAtIndex:0];
self.customSongUrl = [item valueForProperty:MPMediaItemPropertyAssetURL];
[self dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:0)
我有一个类似的问题,问题结果是我的mp4文件目标成员资格复选框未选中,一旦我检查它,文件播放完美。