iOS - Can't stream video from Parse Backend -
recently have created own parse server hosted on heroku using mongolab store data.
my problem saving video parse pffile
, can not seem able stream after saving it.
here exact steps.
first, save video returned uiimagepicker
//get video url let videourl = info[uiimagepickercontrollermediaurl] as? nsurl //create pffile nsdata url let data = nsdata(contentsofurl: videourl!) videofile = pffile(data: data!, contenttype: "video/mp4") //save pffile first, save pfuser pfuser.currentuser()?.setobject(videofile!, forkey: "profilevideo") videofile?.saveinbackgroundwithblock({ (succeeded, error) -> void in print("saved video") pfuser.currentuser()?.saveinbackgroundwithblock({ (succeeded, error) -> void in if succeeded && error == nil { print("user saved") //hide progress bar uiview.animatewithduration(0.5, animations: { () -> void in self.progressbar.alpha = 0 }, completion: { (bool) -> void in self.progressbar.removefromsuperview() }) }else{ //show error if save failed let message = error!.localizeddescription let alert = uialertcontroller(title: "uploading profile picture error!", message: message, preferredstyle: uialertcontrollerstyle.alert) let dismiss = uialertaction(title: "ok", style: uialertactionstyle.cancel, handler: nil) alert.addaction(dismiss) self.presentviewcontroller(alert, animated: true, completion: nil) } }) }, progressblock: { (progress) -> void in self.progressbar.setprogress(float(progress)/100, animated: true) })
this works well. problem lies when retrieve pffile
, try stream video. here code that:
//get url current user self.videofile = pfuser.currentuser()?.objectforkey("profilevideo") as? pffile self.profilevideourl = nsurl(string: (self.videofile?.url)!) //create avplayercontroller let playercontroller = avplayerviewcontroller() //set avplayer url file stored on sever let avplayer = avplayer(url: self.profilevideourl) playercontroller.player = avplayer //present playercontroller self.presentviewcontroller(playercontroller, animated: true, completion: { () -> void in playercontroller.player?.play() })
what ends happening when present playercontroller
this:
why happening when try stream video?
any appreciated!
update
i have tried playing video saved different database using line of code: let videourl = nsurl(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
this confirms format saving pffile
in causing error.
it must line causing error "video/mp4"
not right format : videofile = pffile(data: data!, contenttype: "video/mp4")
update 2
i have taken direct link of .mp4 file located on mongolab , found can play in google chrome, not on safari or iphone.
update 3
i have found issue parse api itself, , had nothing code code works when using original parse backend (the 1 closing down) instead of custom parse server. have no solution should fixed on time.
this code works me
let playercontroller = avplayerviewcontroller() self.addchildviewcontroller(playercontroller) self.view.addsubview(playercontroller.view) playercontroller.view.frame = self.view.frame file!.getdatainbackgroundwithblock({ (moviedata: nsdata?, error: nserror?) -> void in if (error == nil) { let filemanager = nsfilemanager.defaultmanager() let documentspath : anyobject = nssearchpathfordirectoriesindomains(.documentdirectory,.userdomainmask,true)[0] let destinationpath:nsstring = documentspath.stringbyappendingstring("/file.mov") moviedata!.writetofile ( destinationpath string, atomically:true) let playeritem = avplayeritem(asset: avasset(url: nsurl(fileurlwithpath: destinationpath string))) let player = avplayer(playeritem: playeritem) playercontroller.player = player player.play() } else { print ("error on getting movie data \(error?.localizeddescription)") } })
Comments
Post a Comment