ios - Auto capture video using Swift -


i'm working on piece of code responsible starting video recording on button click. when click button camera view opening .startvideocapture() function doesn't start recording.

i strange output every time button pressed:

2015-08-19 16:48:09.588 record video swift[922:227442] snapshotting view has not been rendered results in empty snapshot. ensure view has been rendered @ least once before snapshotting or snapshot after screen updates.

also, there way hide camera view , instead of place there progress bar or something?

class viewcontroller: uiviewcontroller, uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate, uigesturerecognizerdelegate      {         let capturesession = avcapturesession()        var previewlayer : avcapturevideopreviewlayer?         var capturedevice : avcapturedevice?        var imagepicker = uiimagepickercontroller()    override func viewdidappear(animated: bool)   {     if uiimagepickercontroller.issourcetypeavailable(uiimagepickercontrollersourcetype.camera) {         println("capturevideopressed , camera available.")         imagepicker = uiimagepickercontroller()         imagepicker.delegate = self         imagepicker.sourcetype = .camera;         imagepicker.mediatypes = [kuttypemovie!]         imagepicker.allowsediting = false         imagepicker.showscameracontrols = true     }      else      {         println("camera not available.")     } }  @ibaction func rec(sender: anyobject)  {     self.presentviewcontroller(imagepicker, animated: true, completion: nil)     imagepicker.startvideocapture() }  func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject])      {     let tempimage = info[uiimagepickercontrollermediaurl] as! nsurl!     let pathstring = tempimage.relativepath     self.dismissviewcontrolleranimated(true, completion: {})     uisavevideoatpathtosavedphotosalbum(pathstring, self, nil, nil)      }     } 

i had problem , in case using swift 3 ios 10. there couple of ways solve it:

you can call startvideocapture() in completion block of present viewcontroller following:

self.present(self.cameracontroller, animated: true, completion: {     self.cameracontroller.startvideocapture()      if #available(ios 10.0, *) {         timer.scheduledtimer(withtimeinterval: 5, repeats: false) { _ in             self.stopmovementscapture()         }     } else {         // fallback on earlier versions         timer.scheduledtimer(timeinterval: 5,                              target: self,                              selector: #selector(self.stopmovementscapture),                              userinfo: nil,                              repeats: false)     } }) 

another way is, calling startvideocapture() after avcapturesessiondidstartrunning notification fired.

following code observe notification:

notificationcenter.default.addobserver(self, selector: #selector(self.cameraisready), name: .avcapturesessiondidstartrunning, object: nil) 

following function called above notification:

func cameraisready(notification: nsnotification) {     dispatchqueue.main.async {         self.cameracontroller.startvideocapture()          if #available(ios 10.0, *) {             timer.scheduledtimer(withtimeinterval: 5, repeats: false) { _ in                 self.stopmovementscapture()             }         } else {             // fallback on earlier versions             timer.scheduledtimer(timeinterval: 5,                                  target: self,                                  selector: #selector(self.stopmovementscapture),                                  userinfo: nil,                                  repeats: false)         }     } } 

basically make sure device ready capture video. hope helpful!


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -