Maybe a stupid question, but I'm pretty new to Swift and iOS development all together.
I need to play a video on demand, there's a button on the screen that says "PLAY", once you hit that, you play the video, the problem is that the video stays there, on top of everything after being done, so I use this code to hide it:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "hideVideo:", name:AVPlayerItemDidPlayToEndTimeNotification, object: nil)
...
func hideVideo(notification: NSNotification) {
playerController.dismissViewControllerAnimated(false, completion: nil)
}
That hides the video, which is great, but then after trying to play the video again all I get is sound and the video window never comes up.
So my question is, how can I UNdismiss the view controller after it being dismissed?
Here's the code that plays the video for the first and subsequent times:
private func playVideo() {
if playerController.isViewLoaded() { // ALL TIMES AFTER THAT IT SHOULD GO HERE
//create a CMTime for zero seconds so we can go back to the beginning
let seconds : Int64 = 0
let preferredTimeScale : Int32 = 1
let seekTime : CMTime = CMTimeMake(seconds, preferredTimeScale)
self.player.seekToTime(seekTime)
self.player.play()
}
else { // FIRST TIME VIDEO PLAYS
self.presentViewController(playerController, animated: false) {
self.player.play()
}
}
}
Thanks for any help