ios - Video disappears from URL when generating preview image after recompiling app -


i'm creating video app user records video , adds additional information. user can video , information on separate screen.

on information screen i'm trying display still video. works if open information screen within session, when recompile , run application screen shots no longer appear. following error:

nsunderlyingerror=0x162b9350 "the operation couldn’t completed. no such file or directory", nslocalizeddescription=the requested url not found on server.

the video on device somewhere can view via built in 'photos' app.

im using following code perform saving of url string , generating preview image.

saving video url

    let videourl = info[uiimagepickercontrollermediaurl] as! nsurl     let videodata = nsdata(contentsofurl: videourl)             let path = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] as! string     let datapath = path.stringbyappendingpathcomponent("-cached.mov")     videodata.writetofile(datapath, atomically: false)      nsuserdefaults.standarduserdefaults().setobject(datapath, forkey: "datapath")      videonote.url = datapath 

creating preview image

// filepathlocal == videonote.url func videosnapshot(filepathlocal: nsstring) -> uiimage? {      let vidurl = nsurl(fileurlwithpath:filepathlocal string)     let asset = avurlasset(url: vidurl, options: nil)     let generator = avassetimagegenerator(asset: asset)     generator.appliespreferredtracktransform = true      let timestamp: cmtime = asset.duration      var error: nserror?      if let imageref = generator.copycgimageattime(timestamp, actualtime: nil, error: &error){         return uiimage(cgimage: imageref)     } else {         print("image generation failed error \(error)")         return nil     } } 

any appreciated

although never managed code videosnapshot() method work, found use following generate preview shot. downside there not control on timestamp image taken from.

    alassetslibrary().assetforurl(nsurl, resultblock: { (asset) -> void in         if let ast = asset {             return image = uiimage(cgimage: ast.defaultrepresentation().fullresolutionimage().takeunretainedvalue())         }     }) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -