Я использую AVPlayer для загрузки видео из локального хранилища внутри ячейки табличного представления, чтобы показать видео несколько раз.
Работает нормально 16 раз, но при загрузке ячейки 17 раз она не загружается и выдает ошибку
Я пытался использовать видео другого размера, но он все еще не исправлен!
Здесь код
var player : AVPlayer? = nil
var playerLayer : AVPlayerLayer? = nil
var asset : AVAsset? = nil
var playerItem: AVPlayerItem? = nil
var videoURLWithPath = str
let videoURL = NSURL(string: videoURLWithPath)
self.asset = AVAsset(url: videoURL! as URL)
self.playerItem = AVPlayerItem(asset: self.asset!)
NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidFinishPlaying(sender:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.playerItem)
NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidNotLoaded(sender:)), name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime, object: self.playerItem)
NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidNotLoaded(sender:)), name: Notification.Name.AVPlayerItemNewErrorLogEntry, object: self.playerItem)
NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidNotLoaded(sender:)), name: Notification.Name.AVPlayerItemPlaybackStalled, object: self.playerItem)
self.player = AVPlayer(playerItem: self.playerItem)
// When you need to update the UI, switch back out to the main thread
DispatchQueue.main.async {
// Main thread
// Do your UI updates here
let playerViewController = AVPlayerViewController()
playerViewController.videoGravity = AVLayerVideoGravityResizeAspectFill
playerViewController.player = self.player
//playerViewController.showsPlaybackControls = false
view.addChildViewController(playerViewController)
view.didMove(toParentViewController: playerViewController)
playerViewController.view.frame.size.width = self.videoView.frame.width
playerViewController.view.frame.size.height = self.videoView.frame.height
self.videoView.addSubview(playerViewController.view)
if self.player?.rate == nil{
view.showAlert(withMessage: "Vidoe didn't found")
self.continueBtn.isHidden = false
}
self.player!.pause()
}