简体   繁体   中英

AVPlayer with custom UITableViewCell

I have created an AVPlayer object in custom UITableViewCell. As video playing inside UITableViewCell. When I leave that UIViewController, AVPlayer still running in background. How to stop AVPlayer and remove AVPlayerLayer from custom UITableViewCell?

You can pause the player on viewDidDisappear

override func viewDidDisappear(_ animated: Bool) {
       self.playerViewController.player?.pause()
   }
var videoPlayer: AVPlayer!

Assign your UITableViewCell Player to this videoPlayer.

 override func viewDidDisappear(_ animated: Bool) {
      videoPlayer.replaceCurrentItem(with: nil)
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM