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



我正在实现以下方法。

-(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.

最佳答案

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

10-08 17:13