2014-10-04 12 views
5

Sto riproducendo un AVMutableVideoComposition con AVPlayer e poiché IOS8 era perfettamente funzionante. Ma ora il video inizia a suonare e dopo 4 o 5 secondi si ferma, come il buffering o qualcosa del genere, il suono continua a suonare e quando il video termina i loop di AVPlayer e lo riproducono senza interruzioni.AVPlayerItem videoComposition freeze IOS8

Non ho alcun indizio per risolvere questo problema.

Qualsiasi aiuto sarebbe apprezzato,

Grazie

+1

Sto ricevendo lo stesso problema.Possibile essere il suo problema con IOS 8. Ancora non ho trovato alcuna soluzione ..... !!! –

risposta

0

Ho avuto lo stesso problema, ma ho trovato la soluzione.

Si dovrebbe giocare dopo che lo stato di playerItem è cambiato in .ReadyToPlay.

Ho anche risposto allo here, che il problema è simile al problema.

Si prega di vedere come di seguito.

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's 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

Stesso qui, non so se può essere contare come una risposta, ma in ogni caso, basta usare [AVPlayer seekToTime:AVPlayer.currentItem.duration]; per rendere primo loop da soli e ad evitare l'arresto di AVPlayer. È l'unico modo che ho trovato.

0

ho avuto lo stesso problema e ho risolto in questo modo .. Invece di applicare videoComposition per AVPlayerItem direttamente .. ho esportato il mio video con AVAssetExportSession applicare videoComposition, che a sua volta mi dà un URL con un video avendo applicato tutte le mie videoComposition e ora posso usare questo contentURL per riprodurre video su AVPlayer .. Questo funziona come un incantesimo .. L'esportazione del video richiederà tempo, ma come ora la composizione del video non sta accadendo in movimento, funzionerà senza problemi ..

Il seguente codice può essere utilizzato per esportare 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); 

    } 
}); 
}]; 
Problemi correlati