无法在Custome Tableview Cell中播放视频

时间:2016-11-01 12:36:19

标签: ios swift uitableview avplayer tableviewcell

我在单元格容器中创建服装单元格,我需要播放视频但是我尝试使用我的代码将其显示为空...

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell

        let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")
        let player = AVPlayer(url: videoURL! as URL)

        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = cell.bounds

        cell.layer.addSublayer(playerLayer)
        player.play()



        return cell
    }

先谢谢

1 个答案:

答案 0 :(得分:1)

func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - >的UITableViewCell     {

    let cell: FeedCell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell

    let player = playerArray[indexPath.row]
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = CGRect(x:0, y: 0, width: UIScreen.main.bounds.width, height: 200)
   cell.PlayerView?.layer.addSublayer(playerLayer)

}