8

I implemented Video Playback for multiple videos with AVPlayer. When I play next video, sometimes it shows this error messages:

Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo=0x1744796c0 {NSUnderlyingError=0x170055db0 "The operation couldn’t be completed. (OSStatus error -12939.)", NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped}

I found that 11850 error is: AVErrorServerIncorrectlyConfigured which means that

The HTTP server sending the media resource is not configured as expected. This might mean that the server does not support byte range requests.

Please help me with this case, this is my code to play video

- (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];
}
Artem Kulikov
  • 2,250
  • 19
  • 32
Thuc Pham
  • 153
  • 1
  • 11

0 Answers0