8

我使用AVPlayer. 当我播放下一个视频时,有时会显示以下错误消息:

错误域=AVFoundationErrorDomain 代码=-11850“操作已停止”UserInfo=0x1744796c0 {NSUnderlyingError=0x170055db0“操作无法完成。(OSStatus 错误-12939。)”,NSLocalizedFailureReason=服务器未正确配置。,NSLocalizedDescription=操作停止}

我发现11850错误是:AVErrorServerIncorrectlyConfigured这意味着

发送媒体资源的 HTTP 服务器未按预期配置。这可能意味着服务器不支持字节范围请求。

请帮我解决这个问题,这是我播放视频的代码

- (void)playVideoWithUrl:(NSString *) videoUrl 
{
   if (player != nil) {
   [player.currentItem removeObserver:self forKeyPath:@"status"];
   [player.currentItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
   }
AVURLAsset * asset = [[AVURLAsset alloc]initWithURL:[NSURL URLWithString:videoUrl]
                                            options:nil];    
AVPlayerItem * item = [[AVPlayerItem alloc]initWithAsset:asset];
// Add KVO to detech status of loading video
[item addObserver:self
       forKeyPath:@"status"
          options:0
          context:nil];
// Add KVO to detech when playback is loading buffer successfully
[item addObserver:self
       forKeyPath:@"playbackLikelyToKeepUp"
          options:0
          context:nil];
// Detect when playback completed
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[player currentItem]];
[player replaceCurrentItemWithPlayerItem:item];
[player play];
}
4

0 回答 0