[ad_1]
I’ve feed by which totally different classes have a number of movies fro this I exploit UICollectionView with in UIStackView. after I scroll to uicollectionview it take a while to load video and their is lagging when scroll
code to play video in UICollectionview cell
self.videoPreview.layer.sublayers?.forEach {
if $0 is AVPlayerLayer {
$0.removeFromSuperlayer()
}
}
self.participant = AVPlayer(url: self.templateURL)
let playerLayer = AVPlayerLayer(participant: self.participant)
playerLayer.body = self.videoPreview.bounds
self.participant!.isMuted = true
self.videoPreview.layer.addSublayer(playerLayer)
self.participant!.play()
self.layoutSubviews()
self.videoPreview.layoutIfNeeded()
[ad_2]

