I’ve an array of AVURLAsset
movies I merge sequentially by way of AVMutableComposition
. I export the merged video utilizing AVAssetExportSession
, wait till its standing is .accomplished
, after which play again the merged video with AVPlayer
.
The difficulty I am misplaced over is the truth that throughout play again, a sub-video of the merged video, its video image/content material, is clean whereas the audio continues to play. What’s extra complicated is that, once I replay the merged video, it is solely then that the image/content material of that sub video shows.
I attempted including an observer on AVPlayerItem
standing to attend till the merchandise is able to play, nevertheless it nonetheless has that bizarre glitch solely on the primary play again…
Any steerage or workaround can be appreciated.
func export() {
guard let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality) else { return }
exporter.outputURL = outputUrl
exporter.outputFileType = .mp4
exporter.shouldOptimizeForNetworkUse = true
exporter.videoComposition = mainComposition
exporter.exportAsynchronously { [weak self] in
guard let self = self else { return }
if exporter.standing == .cancelled || exporter.standing == .failed {
} else if exporter.standing == .accomplished {
self.play(video: exporter.asset)
}
}
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "standing" {
if let merchandise = object as? AVPlayerItem {
if merchandise.standing == .readyToPlay {
print("Merchandise is able to play")
if !didStartPlayback {
DispatchQueue.major.async {
self.avPlayerPlayback.play()
}
}
} else if merchandise.standing == .failed {
}
}
} else if keyPath == "fee", let participant = object as? AVPlayer {
if participant.fee > 0, !didStartPlayback {
didStartPlayback = true
}
}
}