I have a tableview where I am trying to load videos and play them on viewdidLoad()
Following is the code for load video on Viewdidload
func playVideo(viewController:UIViewController,videoPath:String!, view: UIView) {
guard let path = videoPath else {
debugPrint("video.m4v not found")
return
}
let url = NSURL.fileURL(withPath: path)
let item = AVPlayerItem(url: url)
self.player = AVPlayer(playerItem: item)
self.videoPlayerController = AVPlayerViewController()
self.videoPlayerController.player = self.player
videoPlayerController.view.frame = view.bounds
viewController.addChildViewController(videoPlayerController)
view.addSubview(videoPlayerController.view)
}}
Inside cellForRowAtIndexPath I'm doing the following
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
cell = tableView.dequeueReusableCell(withIdentifier: "trendViewControllerCell", for: indexPath) as! TrendViewTableCell
cell.videoName.text = feeds[indexPath.row].videoTitle
cell.artistName.text = feeds[indexPath.row].artistName
player.playVideo(viewController: self, videoPath: Bundle.main.path(forResource: feeds[indexPath.row].videoUrl, ofType:"mp4")!, view: cell.videoView)
return cell
}
I am trying to resize the AVPlayerController to the view in tableView cell.
On viewDidLoad I am able to see an AVPlayer controller for all views in the cells.
There are about 15 videos
As I scroll down further I see a cancelled buttons and none of the videos load. Sometimes all the videos load and sometimes they don't.
However I don't see this problem in the simulator.
How can I solve this problem? Any help will be appreciated