首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView视频性能

UICollectionView视频性能
EN

Stack Overflow用户
提问于 2017-10-18 04:40:04
回答 1查看 486关注 0票数 0

我有一台苹果电视的UICollectionView。最多有6个单元都显示在同一屏幕上。每个单元有一个不同的循环视频播放。然而,我发现超过2个视频导致非常不稳定的视频播放。如何提高播放视频的性能?

代码语言:javascript
复制
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调用的。

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-20 19:33:22

这个问题是由1920X1080的原始视频的分辨率引起的。降低分辨率解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46802928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档