我正在使用Phonegap的实现来使用视频捕获,并且似乎无法使startVideoCapture正常工作。对于Objective C,我是一个新手,所以如果我不在这里,我深表歉意。听起来startVideoCapture主要用于自定义UI。有什么我可以做的事来自动开始视频录制(因为我正在从其他操作开始视频界面)。这是完整文件的链接:

https://github.com/apache/cordova-plugin-media-capture/blob/master/src/ios/CDVCapture.m

谢谢,

史蒂夫

- (void)captureVideo:(CDVInvokedUrlCommand*)command
{
    NSString* callbackId = command.callbackId;
    NSDictionary* options = [command.arguments objectAtIndex:0];
    NSLog(@"hereeeee");
    if ([options isKindOfClass:[NSNull class]]) {
        options = [NSDictionary dictionary];
    }

    // options could contain limit, duration and mode
    // taking more than one video (limit) is only supported if provide own controls via cameraOverlayView property
    NSNumber* duration = [options objectForKey:@"duration"];
    NSString* mediaType = nil;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        // there is a camera, it is available, make sure it can do movies
        pickerController = [[CDVImagePicker alloc] init];

        NSArray* types = nil;
        if ([UIImagePickerController respondsToSelector:@selector(availableMediaTypesForSourceType:)]) {
            types = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
            // NSLog(@"MediaTypes: %@", [types description]);

            if ([types containsObject:(NSString*)kUTTypeMovie]) {
                mediaType = (NSString*)kUTTypeMovie;
            } else if ([types containsObject:(NSString*)kUTTypeVideo]) {
                mediaType = (NSString*)kUTTypeVideo;
            }
        }
    }
    if (!mediaType) {
        // don't have video camera return error
        NSLog(@"Capture.captureVideo: video mode not available.");
        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:CAPTURE_NOT_SUPPORTED];
        [self.commandDelegate sendPluginResult:result callbackId:callbackId];
        pickerController = nil;
    } else {
        pickerController.delegate = self;
        pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        pickerController.allowsEditing = NO;
        // iOS 3.0
        pickerController.mediaTypes = [NSArray arrayWithObjects:mediaType, nil];

        if ([mediaType isEqualToString:(NSString*)kUTTypeMovie]) {
            if (duration) {
                pickerController.videoMaximumDuration = [duration doubleValue];
            }
            // NSLog(@"pickerController.videoMaximumDuration = %f", pickerController.videoMaximumDuration);
        }

        // iOS 4.0
        if ([pickerController respondsToSelector:@selector(cameraCaptureMode)]) {
            pickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
            // pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
            // pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            // pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
        }
        // CDVImagePicker specific property
        pickerController.callbackId = callbackId;

        SEL selector = NSSelectorFromString(@"presentViewController:animated:completion:");
        if ([self.viewController respondsToSelector:selector]) {
            [self.viewController presentViewController:pickerController animated:YES completion:nil];
        } else {
            // deprecated as of iOS >= 6.0
            [self.viewController presentModalViewController:pickerController animated:YES];
        }
        // Auto start capture
        [pickerController startVideoCapture];
    }
}

最佳答案

我的问题不是使用startVideoRecording,而是在以下情况:

        [self.viewController presentViewController:pickerController animated:YES completion:^(){
            [pickerController startVideoCapture];
        }];


希望这对其他人有帮助。

谢谢,

史蒂夫

08-18 02:36