无法使用iOS默认相机应用程序捕获视频。 Xamarin.iOS

时间:2016-04-30 15:15:13

标签: ios iphone xamarin xamarin.ios

我正在尝试启动默认的iOS相机应用程序进行视频录制,但它不起作用。

每当我启动应用程序时,它都会崩溃,并且不会显示任何错误日志或任何其他错误消息。

如果我将imagePicker.CameraCaptureMode设置为UIImagePickerControllerCameraCaptureMode.Photo,则以下代码可以正常运行。

var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video;
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);

提前致谢

1 个答案:

答案 0 :(得分:4)

我这样做是为了工作:

var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.MediaTypes = new string[]{ UTType.Movie }; // ADD this
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);

您也可以这样设置委托调用:

    imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
    imagePicker.Canceled += Handle_Canceled;

然后创建这些方法:

    protected void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
    {
        //code to handle picking media
    }

    void Handle_Canceled(object sender, EventArgs e)
    {
        imagePicker.DismissViewController(true, null);
    }

<强>更新

在iOS 10中,您需要添加权限并在info.plist

中提供有关您要求获得权限的原因的说明

见这里:

iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash