0

Apple のAVCam ソース コードを使用してカスタム カメラを作成しています。フラッシュのオン/オフを切り替えようとしていますが、機能しません。これが私のコードです。何が問題なのかわかりません。AVCam初心者です。

- (void) toggleFlash:(id)sender {
    dispatch_async([self sessionQueue], ^{
        AVCaptureDevice *currentVideoDevice = [[self videoDeviceInput] device];
        AVCaptureDevicePosition currentPosition = [currentVideoDevice position];
        if(currentPosition == AVCaptureDevicePositionUnspecified || currentPosition == AVCaptureDevicePositionBack) {
            if([currentVideoDevice hasFlash]) {
                [currentVideoDevice lockForConfiguration:nil];
                [currentVideoDevice setFlashMode:AVCaptureFlashModeOn];
                [currentVideoDevice unlockForConfiguration];
            }
        }
    });
}

コードの各行を通過し、これからエラーをログに記録しませんが、それでも運はありません。

4

1 に答える 1

0
- (void) toggleFlash {
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if ([device hasTorch] && [device hasFlash]){
        [device lockForConfiguration:nil];
        [device setTorchMode:!device.torchActive];
        [device setFlashMode:!device.torchActive];
        [device unlockForConfiguration];
    }
}

PS私の場合、トーチ/フラッシュは最初はオフになっています。

于 2014-11-25T06:27:50.557 に答える