xcode - Swift - Can't Dismiss MPMoviePlayerViewController -


i have video opens in mpmovieplayercontroller in app. works great except done button should close player. first time video played done button works great. if pause when watching it, hit done second time try play video, done button doesn't work. have made screen recording here make bit simpler understand: http://1drv.ms/1jcdodc

can help?

this code using:

import uikit import mediaplayer  class maincontent: uiviewcontroller {  //movie player variables     var movieviewcontroller : mpmovieplayerviewcontroller?     var movieplayer : mpmovieplayercontroller!   override func viewdidload() {          super.viewdidload()          //video player setup         nsnotificationcenter.defaultcenter().addobserver(self, selector: "donebuttonclick:", name: mpmovieplayerplaybackdidfinishnotification, object: nil)          var url = nsurl(string: "http://jplayer.org/video/m4v/big_buck_bunny_trailer.m4v")!         movieviewcontroller = mpmovieplayerviewcontroller(contenturl: url)  }    func donebuttonclick(sender:nsnotification?){     let value = uiinterfaceorientation.portrait.rawvalue     uidevice.currentdevice().setvalue(value, forkey: "orientation")     }          //when watch button pressed, present movie player     @ibaction func watchpressed(sender: anyobject)     {self.presentmovieplayerviewcontrolleranimated(movieviewcontroller)}   } 

to fix issue, added mymovieplayerviewcontroller.movieplayer.stop() 'donebuttonclick' function. added mymovieplayerviewcontroller.movieplayer.play() again

@ibaction func watchpressed(sender: anyobject)     {self.presentmovieplayerviewcontrolleranimated(movieviewcontroller)}   } 

so in simple fix! code below:

import uikit import mediaplayer  class maincontent: uiviewcontroller {  //movie player variables     var movieviewcontroller : mpmovieplayerviewcontroller?     var movieplayer : mpmovieplayercontroller!   override func viewdidload() {          super.viewdidload()          //video player setup         nsnotificationcenter.defaultcenter().addobserver(self, selector: "donebuttonclick:", name: mpmovieplayerplaybackdidfinishnotification, object: nil)          var url = nsurl(string: "http://jplayer.org/video/m4v/big_buck_bunny_trailer.m4v")!         movieviewcontroller = mpmovieplayerviewcontroller(contenturl: url)  }   func donebuttonclick(sender:nsnotification?){     let value = uiinterfaceorientation.portrait.rawvalue     uidevice.currentdevice().setvalue(value, forkey: "orientation")     movieviewcontroller?.movieplayer.stop()   }      @ibaction func watchpressed(sender: anyobject){         self.presentmovieplayerviewcontrolleranimated(movieviewcontroller)         movieviewcontroller?.movieplayer.play()     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -