AVPlayerItem videoComposition freeze iOS8

I play AVMutableVideoComposition with AVPlayer and everything was fine with IOS8. But now the video starts playing, and after 4 or 5 seconds it stops, for example, buffering or something like that, the sound continues to play, and when the video ends with AVPlayer loops and plays it perfectly without stopping.

I have no reason to fix this problem.

Any help would be appreciated

thanks

+5
source share
3 answers

I had the same problem, but I got a solution.

You must play after the player status has changed to .ReadyToPlay.

I also answered here , this problem is similar to your problem.

See below.

func startVideoPlayer() { let playerItem = AVPlayerItem(asset: self.composition!) playerItem.videoComposition = self.videoComposition! let player = AVPlayer(playerItem: playerItem) player.actionAtItemEnd = .None videoPlayerLayer = AVPlayerLayer(player: player) videoPlayerLayer!.frame = self.bounds /* add playerItem observer */ player.addObserver(self, forKeyPath: "player.currentItem.status", options: .New, context: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerItemDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: playerItem); self.layer.addSublayer(videoPlayerLayer!) } override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { if keyPath != nil && keyPath! == "player.currentItem.status" { if let newValue = change?[NSKeyValueChangeNewKey] { if AVPlayerStatus(rawValue: newValue as! Int) == .ReadyToPlay { playVideo() /* play after status is changed to .ReadyToPlay */ } } } else { super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context) } } func playerItemDidReachEnd(notification: NSNotification) { let playerItem = notification.object as! AVPlayerItem playerItem.seekToTime(kCMTimeZero) playVideo() } func playVideo() { videoPlayerLayer?.player!.play() } 
0
source

The same thing, I don’t know if it can be considered the answer, but in any case, just use [AVPlayer seekToTime:AVPlayer.currentItem.duration]; do the first cycle yourself and avoid stopping AVPlayer. This is the only way I have found.

0
source

I had the same problem and solved it like that. Instead of directly applying videoComposition to AVPlayerItem .. I exported my video using AVAssetExportSession to apply videoComposition, which in turn gives me Url with a video that has all my videoComposition applications, and now I can use this url content to play video on AVPlayer .. It works like a charm. Exporting the video will take a lot of time, but since the video is no longer happening on the go, it will work smoothly.

The following code can be used to export the video.

 AVAssetExportSession *export = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset1280x720]; export.videoComposition = videoComposition; export.outputURL = [NSURL fileURLWithPath:[[NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID new].UUIDString] stringByAppendingPathExtension:@"MOV"]]; export.outputFileType = AVFileTypeQuickTimeMovie; export.shouldOptimizeForNetworkUse = YES; [export exportAsynchronouslyWithCompletionHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (export.status == AVAssetExportSessionStatusCompleted) { completionHander(export.outputURL, nil); } else { completionHander(nil, export.error); } }); }]; 
0
source

Source: https://habr.com/ru/post/1204001/


All Articles