ios - AVPlayer Crashes on Device When Dismissing View -
i'm having issue avplayer. i've tried many solutions still crashes after move different view.
class guidevideo : baseviewcontroller{ var avplayer: avplayer? var avplayerlayer: avplayerlayer? override func viewdidload() { super.viewdidload() generatevideo() } func generatevideo () { let videourlwithpath = data["videourl"] let videofilepath = nsurl(string: videourlwithpath!) let avasset: avasset = avasset.assetwithurl(videofilepath) as! avasset let avplayeritem = avplayeritem(asset: avasset) avplayer = avplayer(playeritem: avplayeritem) avplayerlayer = avplayerlayer(player: avplayer) avplayerlayer!.frame = self.videoview.bounds self.videoview.layer.addsublayer(avplayerlayer) avplayer!.play() }
i've tried removing observers since assume crash related nil observer.
override func viewwilldisappear(animated: bool) { dispatch_async(dispatch_get_main_queue(),{ if self.avplayerlayer != nil { self.avplayerlayer!.player.pause() nsnotificationcenter.defaultcenter().removeobserver(self.avplayerlayer!) self.avplayerlayer!.removefromsuperlayer() self.avplayerlayer = nil } self.avplayer!.pause() self.avplayer = avplayer() }) super.viewwilldisappear(animated) }
nothing works , crash provides no data. either crashes without indicating line or general
thread 1: exc_bad_access * import thing note crash happens on iphone 6/6+. our iphone 5c handles class well. * crash after moving view controller or different navigation stack, few seconds after view had been dismissed.
thank you, been sitting on better part of 2 days now.
edit: issue apparently related swreveal. deallocates instances before lifecycle over. accepted best solution, problem related swreveal.
- try using mpmovieplayercontroller instead of avplayer, simple solutions, mpmovieplayercontroller has easier api.
- make mpmovieplayercontroller global instance making accessible through whole app, , initialize when need it.
- try playing videos locally first , check if solves problem
Comments
Post a Comment