[iPhone Dev] Camera Swap
// Button Event
-(IBAction)CameraSwap:(id)sender
{
NSArray *Current_inputs = self._captureSession.inputs;
for ( AVCaptureDeviceInput *old_input in Current_inputs) {
AVCaptureDevice *device = old_input.device;
if ([device hasMediaType:AVMediaTypeVideo]) {
AVCaptureDevicePosition position = device.position;
AVCaptureDevice *newCamera = nil;
AVCaptureDeviceInput *newInput = nil;
if (position == AVCaptureDevicePositionFront) {
newCamera = [self cameraWithPosition:AVCaptureDevicePositionBack];
} else {
newCamera = [self cameraWithPosition:AVCaptureDevicePositionFront];
}
newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil];
// Config Start
[self._captureSession beginConfiguration];
[self._captureSession removeInput:old_input];
[self._captureSession addInput:newInput];
[self._captureSession commitConfiguration];
break;
}
}
}
-(AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position {
NSArray *Camera_devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in Camera_devices) {
if (device.position == position) {
return device;
}
}
return nil;
}
댓글
댓글 쓰기