2014-10-04 19 views
5

AVPlayer ile AVMutableVideoCompozition oynuyorum ve IOS8'den beri her şey mükemmel. Ama şimdi video oynamaya başlar ve 4 veya 5 saniye sonra, örneğin, tamponlama veya böyle bir şey gibi durur, ses çalmaya devam eder ve video AVPlayer döngüler bittiğinde ve durmaksızın düzgün çaldığında.AVPlayerItem videoCompozisyon dondurma IOS8

Bu sorunu gidermek için hiçbir fikrim yok. Herhangi bir yardım takdir edilecektir

,

olabilir ki eğer bir cevap gibi saymak biliyorum ama yine de, sadece [AVPlayer seekToTime:AVPlayer.currentItem.duration]; kendiniz ve ilk döngü yapmak kullanmayın, burada size aynı

+1

Aynı sorunu alıyorum. IOS 8 ile ilgili sorunu olabilir. Yine de bir çözüm bulamıyorum ..... !!! –

cevap

0

Aynı sorun vardı, ancak çözümü aldım.

PlayerItem'in durumu .ReadyToPlay olarak değiştirildikten sonra oynamalısınız.

Ayrıca, here numaralı yanıtı da verdim, bu sorun sorununuza benzer.

Lütfen aşağıdaki şekile bakınız.

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

ederiz AVPlayer'ın durmasını engelleyin. Bu sadece bulduğum yol.

0

ben de aynı sorunu vardı ve ben bunu şu şekilde çözüldü .. Bunun yerine .. benim Video sırayla bir video ile bana bir Url verir videoComposition, uygulamak AVAssetExportSession kullanılarak dışa doğrudan AVPlayerItem için videoComposition uygulanması benim videoComposition tüm uygulamalı ve şimdi ben bu contentURL AVPlayer video oynatmak için kullanabilirsiniz .. Bu çekicilik gibi çalışır .. Dışa aktarma video zaman alacaktır ama şimdi video kompozisyonu hareket halindeyken oluşmuyor, sorunsuz çalışacaktır ..

Aşağıdaki kod, video dışa aktarmak için kullanılabilir ..

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); 

    } 
}); 
}];