AVPlayerViewController in UICollectionViewCell bug?

£可爱£侵袭症+ 提交于 2019-12-03 22:28:46
Erik Auranaune

You need a new aPlayer and moviePlayerController for each cell which has the video in it. Something like this should do it:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        var videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellVideo", forIndexPath: indexPath) as? CollectionViewCell

        var aPlayer = AVPlayer()
        let moviePlayerController = AVPlayerViewController()

        let post = self.arrayOfDetails[indexPath.row]

        var myUrl = post.image // post.image is image url

        let fileUrl = NSURL(string: post.image)

        aPlayer = AVPlayer(URL: fileUrl)

        moviePlayerController.player = aPlayer
        moviePlayerController.view.frame = CGRectMake(8, 8, videoCell!.frame.size.width-16, 310)
        moviePlayerController.videoGravity = AVLayerVideoGravityResizeAspectFill
        moviePlayerController.view.sizeToFit()
        moviePlayerController.showsPlaybackControls = true
        videoCell!.addSubview(moviePlayerController.view)

        return videoCell!
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!