I am building an app similar to Vine and Twitter. I want to embed an AVPlayerViewController inside a UITableViewCell for easy video playback.
I used UITableViewCell.CellStyle to add some UI elements to the cell. The same process doesn't work for AVPlayerViewController.
let video: AVPlayerViewController = {
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL!)
let av = AVPlayerViewController()
av.player = player
av.videoGravity = AVLayerVideoGravity.resizeAspect
av.view.frame = CGRect(x:0, y:96, width: screenWidth, height: (screenWidth+7))
self.addChild(av)
self.addSubview(av.view)
av.didMove(toParent: self)
return av
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
addSubview(pic)
addSubview(title)
addSubview(video)
addSubview() works fine for adding an image, labels, and buttons to the table cell, but it won't work for AVPlayerViewController because it is not a UIView.
The error message is: Cannot convert value of type 'AVPlayerViewController' to expected argument type 'UIView'. How can I add video to the cell style?