AVPlayer无法播放

时间:2018-07-18 19:18:46

标签: swift4 uicollectionviewcell avplayer

我有UICollectionView和UICollectionViewCell

我在IUCollectionViewCell中创建了AVPlayer

当我单击单元格上的AVPlayer Play播放但AVPlayer无法播放时。

UICollectionView单元格;

class UserProfilePhotoCell: UICollectionViewCell {

    var avPlayer: AVPlayer?
    var avPlayerViewConroller: AVPlayerViewController?
    var avPlayerLayer: AVPlayerLayer?
    var avPlayerItem: AVPlayerItem?
    var player2: AVPlayer?

    var post: ProfileVideo? {
        didSet{
            print(post?.videoPath)

            let url = NSURL(string: (post?.videoPath)!)
            player2 = AVPlayer(url: url! as URL)
            let playerLayer = AVPlayerLayer(player: player2)
            playerLayer.frame = bounds
            playerLayer.videoGravity = .resizeAspect
            self.layer.addSublayer(playerLayer)


        }
    }


    func baslat(){
       player2?.play()
       print("AVPlayer Play") 
    }

    func durdur(){
        player2?.pause()
    }


    override init(frame: CGRect) {
        super.init(frame: frame)
        }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

CollectionView;

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    var cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! UserProfilePhotoCell
    cell.baslat()

}

0 个答案:

没有答案