I am extremely new to Swift and iOS, so please forgive my ignorance.
I am trying to automatically close AVPlayer when the video is playing. I decided to attach the "playerDidFinishPlaying" listener to receive the notification, but as soon as I find it, I cannot find the method / event to close the controller. I want to emulate the action of clicking Finish.
Here is a small piece of code. I hope this is enough. If not, I can provide additional information.
let destination = segue.destinationViewController as! AVPlayerViewController
let url = NSURL(string: "video url")
destination.player = AVPlayer(URL: url!)
destination.player?.play()
I added the following notice, but again, I'm not sure what to do with it when I have it ...
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:",
name: AVPlayerItemDidPlayToEndTimeNotification,
object: destination.player!.currentItem)
func playerDidFinishPlaying(note:NSNotification){
print("finished")
}
Finally, I know that I need to remove the observer, but I'm not sure when and where to do it. Any help is appreciated.