尝试设置 SetVideoFrameRate 时出现 xamarin 错误

xamarin error when trying set SetVideoFrameRate

我正在研究 xamarin。我正在使用 MediaRecorder,我只想设置帧速率,但是当我设置它时 recorder.SetVideoFrameRate(30); 我得到

的错误

Java.Lang.IllegalStateException:

我不确定它的设备是否无法处理它,或者是否有某种方法可以让它工作。我只是在使用简单的 MediaRecorder。

MediaRecorder recorder;

video.StopPlayback();

recorder = new MediaRecorder();
//--
recorder.SetVideoFrameRate(30);
// recorder.SetCaptureRate(150);
recorder.SetVideoSource(VideoSource.Camera);
recorder.SetAudioSource(AudioSource.Mic);
recorder.SetOutputFormat(OutputFormat.Default);
recorder.SetVideoEncoder(VideoEncoder.Default);
recorder.SetAudioEncoder(AudioEncoder.Default);
recorder.SetOutputFile(path);
recorder.SetPreviewDisplay(video.Holder.Surface);
recorder.Prepare();
recorder.Start();

您不能在 SetOutputFormat 之前调用 SetVideoFramerate。将该方法调用移到 SetOutputFormat 下,它将起作用。

recorder = new MediaRecorder();
recorder.SetVideoSource(VideoSource.Camera);
recorder.SetAudioSource(AudioSource.Mic);
recorder.SetOutputFormat(OutputFormat.Default);
recorder.SetVideoFrameRate(30); // Move it here

Android 实际上有一个很棒的文档告诉你每个方法可以抛出什么异常。这是引自 MediaRecorder's page:

Throws

IllegalStateException if it is called after prepare() or before setOutputFormat(). NOTE: On some devices that have auto-frame rate, this sets the maximum frame rate, not a constant frame rate. Actual frame rate will vary according to lighting conditions.