File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,31 @@ - (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position
100100 return nil ;
101101}
102102
103+ - (void )changeCameraWithPositon : (AVCaptureDevicePosition)position {
104+ AVCaptureDevice *newCamera = [self cameraWithPosition: position];
105+ AVCaptureDeviceInput *newInput = [AVCaptureDeviceInput deviceInputWithDevice: newCamera error: nil ];
106+ if (newInput != nil ) {
107+ [self .session beginConfiguration ];
108+ // 先移除原来的input
109+ [self .session removeInput: self .deviceInput];
110+ if ([self .session canAddInput: newInput]) {
111+ [self .session addInput: newInput];
112+ self.deviceInput = newInput;
113+ }else {
114+ // 如果不能加现在的input,就加原来的input
115+ [self .session addInput: self .deviceInput];
116+ }
117+
118+ self.session .sessionPreset = self.resolutionRatioValue ;
119+ // 保存Connection,用于SampleBufferDelegate中判断数据来源(video or audio?)
120+ _videoConnection = [_videoOutput connectionWithMediaType: AVMediaTypeVideo];
121+ [_videoConnection setVideoOrientation: AVCaptureVideoOrientationPortrait];
122+
123+ [self .session commitConfiguration ];
124+ }
125+
126+ [self setCameraFPS: 15 ];
127+ }
103128/* *
104129 切换前后摄像头
105130 */
@@ -232,6 +257,9 @@ - (void)setupVideoCapture {
232257 if ([_session canSetSessionPreset: self .resolutionRatioValue]) {
233258 // 设置分辨率
234259 _session.sessionPreset = self.resolutionRatioValue ;
260+
261+ // 设置传入的position
262+ [self changeCameraWithPositon: self .devicePosition];
235263 }
236264 return ;
237265 }
You can’t perform that action at this time.
0 commit comments