ios - Switch from back camera to front camera while recording -
so have custom camera works. can record video , file etc. can choose camera use; front or back. however, when press record can switch between front camera , camera , still records file until hit stop recording. hope makes sense.
my code switching cameras:
@ibaction func changecamera(sender: anyobject) { println("change camera") self.recordbutton.enabled = false dispatch_async(self.sessionqueue!, { var currentvideodevice:avcapturedevice = self.videodeviceinput!.device var currentposition: avcapturedeviceposition = currentvideodevice.position var preferredposition: avcapturedeviceposition = avcapturedeviceposition.unspecified switch currentposition{ case avcapturedeviceposition.front: preferredposition = avcapturedeviceposition.back case avcapturedeviceposition.back: preferredposition = avcapturedeviceposition.front case avcapturedeviceposition.unspecified: preferredposition = avcapturedeviceposition.back } var device:avcapturedevice = viewcontroller.devicewithmediatype(avmediatypevideo, preferringposition: preferredposition) var videodeviceinput: avcapturedeviceinput = avcapturedeviceinput(device: device, error: nil) self.session!.beginconfiguration() self.session!.removeinput(self.videodeviceinput) if self.session!.canaddinput(videodeviceinput){ nsnotificationcenter.defaultcenter().removeobserver(self, name:avcapturedevicesubjectareadidchangenotification, object:currentvideodevice) viewcontroller.setflashmode(avcaptureflashmode.auto, device: device) nsnotificationcenter.defaultcenter().addobserver(self, selector: "subjectareadidchange:", name: avcapturedevicesubjectareadidchangenotification, object: device) self.session!.addinput(videodeviceinput) self.videodeviceinput = videodeviceinput }else{ self.session!.addinput(self.videodeviceinput) } self.session!.commitconfiguration() dispatch_async(dispatch_get_main_queue(), { self.recordbutton.enabled = true self.stoprecording.enabled = true }) }) }
Comments
Post a Comment