ios - Save video on the gallery and store the path to the video -


i have app in user can record video, video saved in photo gallery, , store path video in future user see again video inside app. problem method use think it's giving me kind of temporary path, , after days, video still in gallery, path not valid anymore , make app crash. code i'm using:

func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject]) {     let mediatype: string = info["uiimagepickercontrollermediatype"] as! string     if mediatype == "public.movie" {         let tempimageurl = info[uiimagepickercontrollermediaurl] as! nsurl!         let pathstring = tempimageurl.relativestring         self.dismissviewcontrolleranimated(true, completion: {})         if picker.sourcetype == uiimagepickercontrollersourcetype.photolibrary {             self.videopath = pathstring             // save path in db         } else {             videomanager.savevideo(tempimageurl, oncomplete: { (path) -> void in                 self.videopath = path                 // save path in db             })             var filemanager: nsfilemanager = nsfilemanager()             filemanager.removeitematpath(pathstring!, error: nil)         }     } } 

and videomanager.savevideo method code following:

func savevideo(videourl: nsurl, oncomplete:((path: string) -> void)) {     var assetslibrary: alassetslibrary = alassetslibrary()     assetslibrary.writevideoatpathtosavedphotosalbum(videourl, completionblock: { (asseturl: nsurl!, error: nserror!) -> void in         var path: string = error == nil ? "\(asseturl)" : kemptystring         oncomplete(path: path)     }) } 

i don't know i'm doing wrong, i've tried method uisavevideoatpathtosavedphotosalbum without success.. ideas?

for giving little more information, when video selected gallery, url following one:

file:///private/var/mobile/containers/data/application/d2e8e31b-cea0-43b0-8ef9-1820f6bde4a9/tmp/trim.ad855155-ab78-4a16-9aa8-df2b3f39824e.mov 

and when record new video using camera, first have url:

file:///private/var/mobile/containers/data/application/d2e8e31b-cea0-43b0-8ef9-1820f6bde4a9/tmp/capture/capturedvideo.mov 

and when writevideoatpathtosavedphotosalbum returns url like:

assets-library://asset/asset.mov?id=958507b5-1353-4ddc-bc07-d9cbc6126657&ext=mov 

both of them work, days later stop working.

ok found solution, thing can't access directly photo gallery stored url, got use assetlibrary.assetforurl method, missing. in end imagepickercontroller delegate method this:

func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject]) {     let mediatype: string = info["uiimagepickercontrollermediatype"] as! string     if mediatype == "public.movie" {         self.dismissviewcontrolleranimated(true, completion: {})         if picker.sourcetype == uiimagepickercontrollersourcetype.photolibrary {             let tempimageurl = info[uiimagepickercontrollerreferenceurl] as! nsurl!             self.videopath = tempimageurl.absolutestring         } else {             let tempimageurl = info[uiimagepickercontrollermediaurl] as! nsurl!             videomanager.savevideo(tempimageurl, oncomplete: { (path) -> void in                 self.videopath = path             })         }     }  } 

i missing when record video, got obtain url using:

let tempimageurl = info[uiimagepickercontrollermediaurl] as! nsurl! 

but when video have do:

let tempimageurl = info[uiimagepickercontrollerreferenceurl] as! nsurl! 

hope helps!!


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -