错误域 = AVFoundationErrorDomain 代码 = -11800 “操作无法完成。错误域 = NSOSStatusErrorDomain 代码 = -16170 “(空)”

我在我的聊天应用程序中使用 AVPlayer,但在选定的音频文件中出现了错误,但音频文件在浏览器中正确播放。

Error Domain=AVFoundationErrorDomain Code=-11800“操作无法完成” UserInfo={NSUnderlyingError=0x60800024fde0 {Error Domain=NSOSStatusErrorDomain Code=-16170 "(null)"}, NSLocalizedFailureReason=发生未知错误 (-16170), NSLocalizedDescription=操作无法完成}

我正在实施以下方法。

-(void)setupAVPlayerForURL:(NSURL*)url
 {
    AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
    AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
    playerAud = nil;
    playerAud = [AVPlayer playerWithPlayerItem:anItem];
    [self startTimer];
    [playerAud play];
    [anItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudioPlay) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
}

And also implement the fallowing observer.

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    //// playerAud is instance of AVPlayer 
    if (object == playerAud.currentItem && [keyPath isEqualToString:@"status"]) {
        if (playerAud.currentItem.status == AVPlayerItemStatusFailed) {
            NSLog(@"------player item failed:%@",playerAud.currentItem.error);
        }
    }
}

It prints the above error.
stack overflow Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed. Error Domain=NSOSStatusErrorDomain Code=-16170 "(null)"
原文答案

答案:

作者头像

就我而言,我使用 http url.Set NSAllowsArbitraryLoads to YES 修复错误。