0

I'm having the same problem as this question but I don't see where I'm going wrong.

It still remains on the last frame of the video on the external display.

iOS Swift App AVPlayerController dismiss not working on external display

Unfortunately, I don't have enough reputation points to comment on the other question.

Is it because I don't have an AVPlayerItem?

let fourVideoViewController = AVPlayerViewController()    

@IBAction func fourVideoPlayButton(_ sender: Any) {

    let fourVideoURL = Bundle.main.url(forResource: "Four Animation", 
withExtension: "mov")!
    let fourPlayer = AVPlayer(url: fourVideoURL as URL)

    fourVideoViewController.player = fourPlayer

    NotificationCenter.default.addObserver(self, selector: 
#selector(playerDidFinishPlaying), name: 
NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: 
fourVideoViewController.player?.currentItem)

    self.present(fourVideoViewController, animated: true) {
        self.fourVideoViewController.player!.play()
    }
}


@objc func playerDidFinishPlaying(note: NSNotification) {

    fourVideoViewController.dismiss(animated: true, completion: nil)
    fourVideoViewController.view.removeFromSuperview()
    self.presentedViewController?.dismiss(animated: true, completion: nil)
}
J.Kearney
  • 7
  • 1
  • 7

2 Answers2

0

Can you try to dismiss inside your playerDidFinishPlaying function

self.navigationController?.popToRootViewController(animated: true)

OR

self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)

  • Still no luck. The 2nd option gave me the error Fatal error: Unexpectedly found nil while unwrapping an Optional value – J.Kearney Dec 28 '18 at 04:10
0

Try this

fourVideoViewController.removeFromParentViewController() fourVideoViewController.view.removeFromSuperview() self.presentedViewController?.dismiss(animated: true, completion: nil)

iampikuda
  • 11
  • 1