在UItableView单元格swift中播放视频

时间:2016-11-02 23:50:05

标签: ios swift

我正在尝试在TableView Cell中播放视频。我正在使用此代码但是当我运行时什么都不会出现。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "myCell")!
    let videoURL = NSURL(string: "http://techslides.com/demos/sample-videos/small.mp4")
    let player = AVPlayer(url: videoURL! as URL)
    let playerLayer = AVPlayerLayer(player: player)

    playerLayer.frame = myCell.bounds
    myCell.layer.addSublayer(playerLayer)
    player.play()

    return myCell
}

2 个答案:

答案 0 :(得分:1)

根据我之前的评论请在info.plist中启用App transport security。

以下是视觉设置:

enter image description here

答案 1 :(得分:0)

您需要转到info.plist并允许App Transport Security。

相关问题