ios - MPMoviePlayerController Black Screen when called in shared session -
i have playvideo() method in here:
func playvideo() { let url = nsurl(string: "http://mtc.cdn.vine.co/r/videos_r2/20660994a41184015287536758784_sw_webm_14252654515363566800065.mp4?versionid=x5uve9shovypw7z7.vneppyihefx_uwj") //let url = nsurl(string: videourls[videonumber]) //println(videourls[videonumber]) movieplayer = mpmovieplayercontroller(contenturl: url) if let player = movieplayer { player.view.frame = cgrect(x: 0, y: 0, width: 300, height: 300) player.view.center = self.view.center player.preparetoplay() player.scalingmode = .aspectfill player.controlstyle = .none self.view.addsubview(player.view) player.play() } }
when directly call viewdidload works without problem. when tried call in shared session that:
var task = nsurlsession.sharedsession().datataskwithurl(url!, completionhandler: { data,response,error -> void in if(error == nil) { var err :nserror? var jsonresult : nsdictionary = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers, error: &err) nsdictionary! var records: nsarray = (jsonresult["data"]?["records"]) nsarray for(var i=0;i<records.count;i++) { var strvideo = (records[i]["videolowurl"] string); videourls.append(strvideo) } } else { println("error") } }) task.resume()
it shows black screen , there no sound or nothing else.
i know calls playvideo() method not work right.
what problem ?
this top of head completion handler not called on main thread. ui stuff must done on main thread.
dispatch main queue using:
dispatch_async(dispatch_get_main_queue()) { self.playvideo() }
Comments
Post a Comment