我有Apple TV的UICollectionView。最多6个单元格全部显示在同一屏幕上。每个小区都有不同的循环视频播放。但是,我发现只有2个视频导致视频播放非常不连贯。如何提高播放视频的效果?
class ExerciseCell: UICollectionViewCell {
@IBOutlet private weak var stationNumberLabel: UILabel!
@IBOutlet private weak var exerciseNameLabel: UILabel!
private var looperPlayer:AVPlayerLooper!
var exercise:ExerciseData! {
didSet {
self.stationNumberLabel.text = exercise.stationNumber
self.exerciseNameLabel.text = exercise.exerciseName
playVideo()
}
}
private func playVideo()
{
//if let videoURL = URL(string:self.exercise.videoURL)
if let videoPath = Bundle.main.path(forResource: self.exercise.videoName, ofType: "mp4")
{
//let playerItem = AVPlayerItem(url: videoURL)
let playerItem = AVPlayerItem(url: URL(fileURLWithPath: videoPath))
let queuePlayer = AVQueuePlayer(playerItem: playerItem)
let playerLayer = AVPlayerLayer(player: queuePlayer)
playerLayer.frame = self.layer.bounds
playerLayer.videoGravity = .resize
playerLayer.player = queuePlayer
self.looperPlayer = AVPlayerLooper(player: queuePlayer, templateItem: playerItem)
self.layer.insertSublayer(playerLayer, at: 0)
queuePlayer.volume = 0.0
queuePlayer.play()
}
else
{
self.layer.sublayers?.forEach { $0.removeFromSuperlayer() }
}
}}
以上是从UICollectionViewController
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ExerciseCell
cell.exercise = self.exercisesArray[indexPath.row]
return cell
}
答案 0 :(得分:0)
该问题是由1920X1080的源视频的分辨率引起的。降低分辨率解决了这个问题。