Xamarin相机渲染器可以';t在iOS 14更新后录制视频

Xamarin相机渲染器可以';t在iOS 14更新后录制视频,ios,xamarin,xamarin.forms,xamarin.ios,Ios,Xamarin,Xamarin.forms,Xamarin.ios,我正在Xamarin窗体上编程,并创建了一个iOS渲染器。因此,在iOS 14更新后,我的应用程序开始录制,但之后立即停止。在iOS 13上,该记录运行得非常完美 在iOS 14上解决问题的步骤: 显示相机预览 用户单击开始记录按钮 录制视频状态图标显示在iPhone顶部栏上(本机) 捕获立即停止 iOS 13上的步骤: 显示相机预览 用户单击开始记录按钮 录制视频状态图标显示在iPhone顶部栏上(本机) 捕获在5秒后停止(我设置的时间限制) 下面是我正在使用的渲染器代码: private

我正在Xamarin窗体上编程,并创建了一个iOS渲染器。因此,在iOS 14更新后,我的应用程序开始录制,但之后立即停止。在iOS 13上,该记录运行得非常完美

在iOS 14上解决问题的步骤:

  • 显示相机预览
  • 用户单击开始记录按钮
  • 录制视频状态图标显示在iPhone顶部栏上(本机)
  • 捕获立即停止
  • iOS 13上的步骤:

  • 显示相机预览
  • 用户单击开始记录按钮
  • 录制视频状态图标显示在iPhone顶部栏上(本机)
  • 捕获在5秒后停止(我设置的时间限制)
  • 下面是我正在使用的渲染器代码:

     private void StartVideo(object sender, EventArgs e)
        {
            Element.completed = new TaskCompletionSource<VideoViewResult>();
    
            NSUrl url = new NSUrl(PathFile, true);
    
            if (avDel == null) avDel = new AVCaptureFileOutputRecording();
            if (output == null) output = new AVCaptureMovieFileOutput();
    
            var stillImageOutput = new AVCaptureStillImageOutput()
            {
                OutputSettings = new NSDictionary()
            };
    
            output.MaxRecordedDuration = CoreMedia.CMTime.FromSeconds(5, 1); // time limit
            // output.MaxRecordedDuration = CoreMedia.CMTime.FromSeconds(50000, 1);  //not working too
    
            if (Control.CaptureSession.CanAddOutput(output)) Control.CaptureSession.AddOutput(output);
    
            output.StartRecordingToOutputFile(url, avDel);
    
            avDel.StopRecord += StopRecording;
        }
    
    private void StartVideo(对象发送方,事件参数e)
    {
    Element.completed=new TaskCompletionSource();
    NSUrl url=新的NSUrl(路径文件,true);
    如果(avDel==null)avDel=new AVCaptureFileOutputRecording();
    如果(output==null)output=new AVCaptureMovieFileOutput();
    var stillImageOutput=新的AVCaptureSillImageOutput()
    {
    OutputSettings=新建NSDictionary()
    };
    output.MaxRecordedDuration=CoreMedia.CMTime.FromSeconds(5,1);//时间限制
    //output.MaxRecordedDuration=CoreMedia.CMTime.FromSeconds(50000,1);//也不工作
    if(Control.CaptureSession.CanAddOutput(输出))Control.CaptureSession.AddOutput(输出);
    output.StartRecordingToOutputFile(url,avDel);
    avDel.StopRecord+=停止录制;
    }
    

    我已经分析了权限,但还行。有什么办法解决这个问题吗?谢谢。

    问题出在视频文件的位置

    旧代码:

    private static string GetOutputPath()
    {
        string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyApp");
        Directory.CreateDirectory(folder); 
                
        return Path.Combine(folder, $"{Guid.NewGuid().ToString("N")}.{VideoFormat}");
    }
    
    新代码:

    private static NSUrl GetOutputPath()
    {
       NSUrl url;
    
       if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
          url = NSFileManager.DefaultManager.GetTemporaryDirectory().Append($"{Guid.NewGuid():N}.{VideoFormat}", false);
       else
       {
          string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyApp");
          Directory.CreateDirectory(folder);
    
          var PathFile = Path.Combine(folder, $"{Guid.NewGuid():N}.{VideoFormat}");
    
          url = new NSUrl(PathFile, true);
        }
    
        return url;
    }
    
    现在视频录制正确了

    应用程序在用户权限(NSPhotoLibraryUsageDescription/NSPhotoLibraryAddUsageDescription)下可以完全访问照片

    我开始使用一个临时文件夹,我的问题得到了解决。但是,最好使用个人目录(Environment.SpecialFolder.Personal),就像以前版本的iOS一样

    FYI:应该“分析”