0

I'm trying to play a video in TableView Cell.I'm using this code but when I run nothing will appear.

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
}
Wayne Ellery
  • 7,888
  • 1
  • 28
  • 45
  • In think you forgot to enable `App Transport Security` so please use http://stackoverflow.com/a/33712228/1142743 to enable it – Vinodh Nov 03 '16 at 02:16
  • Thank you so much.It worked. – Bechir Kaddech Nov 03 '16 at 18:07
  • I added my answer please accept it. so for others it will be useful – Vinodh Nov 04 '16 at 02:10
  • Possible duplicate of http://stackoverflow.com/a/33712228/1142743 – Eric Aya Nov 04 '16 at 10:14
  • There is something fundamentally wrong with the code. You'll be adding extra video player layers every time you a cell is reused. I suggest creating a custom cell that already has a videoplayer as a part of it. Or one videoplayer that runs in all the cells – DatForis Nov 04 '16 at 13:31

2 Answers2

1

As per my previous comment Please enable App transport security in info.plist .

Here are the settings visually:

enter image description here

Vinodh
  • 5,262
  • 4
  • 38
  • 68
0

You need to go to info.plist and allow App Transport Security.

Travis Whitten
  • 44
  • 2
  • 11