class MyClass: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
var playerTimer = NSTimer()
override func viewDidAppear(animated:Bool) {
super.viewDidAppear(true)
presentViewController(GameViewController1(), animated: false, completion: nil)
let fileURL = NSURL(fileURLWithPath: "SomeFile.mp4")
playerView = AVPlayer(URL: fileURL)
playerViewController.player = playerView
self.presentViewController(playerViewController, animated: false){
self.playerViewController.showsPlaybackControls = false
self.playerViewController.player?.play()
self.playerTimer = NSTimer.scheduledTimerWithTimeInterval(4.2, target: self, selector:Selector("stopAfter4seconds:"), userInfo: nil, repeats: false)
}
}
func stopAfter4seconds(timer: NSTimer){
playerViewController.player = nil
playerViewController.removeFromParentViewController()
playerTimer.invalidate()
playerViewController.presentViewController(GameViewController1(), animated: false, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
After I play a video on 'MyClass' (Class Above)
I then remove the view and present my GameContollerView1 which has the GameScene.
(Class below)
class GameViewController1: UIViewController, ADBannerViewDelegate {
@IBOutlet var skView: SKView!
override func viewDidLoad() {
super.viewDidLoad()
if skView.scene == nil {
let scene = GameScene(size: skView.bounds.size)
skView.presentScene(scene)
}
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return UIInterfaceOrientationMask.AllButUpsideDown
} else {
return UIInterfaceOrientationMask.All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
My Initial Problem is that when I present the class 'GameViewController1' I get the error:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
at this line:
if skView.scene == nil {
So it's telling me that my SKView! is nil, which as you can see by my if statement, is what i was looking for anyways.
The weirdest part about this, is that when I skip over 'MyClass' and point my StoryBoard Entry Point to the GameViewContoller1 first, all the code plays correctly.
Does the AVPlayer() have something to do with this? Logically my code should work but for some unknown reason.. it's not. any help would be extremely appreciated.