AVPlayerItem status AVPlayerStatusFailed when playing video
Asked Answered
C

0

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];
}
Centigrade answered 3/11, 2015 at 7:33 Comment(5)
Is it solved or not?Alaster
No, I haven't found the root cause yet. But I found another solution for my own project, I downloaded and played videos from Document directory instead of playing them directly from server.Centigrade
ok, thanks for your reply!Alaster
Have you found a workaround for server?Dugong
#33823911Snake

© 2022 - 2024 — McMap. All rights reserved.