I'm currently writing a custom video player using AVPlayer. The video plays fine and works in 99% of cases. But when seeking, I occasionally run into an error. My AVPlayerItem's status changes to AVPlayerItemStatusFailed, and its "error" property is set to:
Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x541da00 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}
The error occurs on iOS 4.0.1 when seeking forward in an HTTP Live Stream. It happens more often when the phone is on 3G or the bitrate of the stream is high. To reproduce, play an HTTP Live Stream with AVPlayer on iOS 4.0.1 and seek forward past the loaded buffer -- the error occurs ~50% of 开发者_如何学JAVAthe time.
I found in AVError.h that AVFoundation error code -11819 corresponds to AVErrorMediaServicesWereReset ("The operation could not be completed because media services became unavailable") .
Does anyone know what causes this error and how to fix it? I know a fix is possible because MPMoviePlayerViewController (which uses AVPlayer) does not exhibit the bug. Unfortunately, due to external constraints, I cannot use MPMoviePlayer in my code.
Thanks!
It turns out AVPlayer is very NON-threadsafe when seeking forward in an HTTP Live Stream on iOS 4.0.1 . Some of my code called setNeedsDisplay or otherwise invoked system UI code, which "interrupted" the player while it was drawing. The solution was not to update the view between when the user seeks to a position and when the player begins playing from that position. Fortunately, this seems fixed in 4.3+.
精彩评论