【发布时间】:2014-10-21 15:09:47
【问题描述】:
我正在尝试修改链接到此处的示例代码,它将使用 Xamarin 录制视频:http://developer.xamarin.com/recipes/android/media/video/record_video/
具体来说,我正在尝试设置视频大小,所以我修改了StartRecorder 方法来指定支持的视频大小:
private void StartRecorder()
{
try
{
_video.StopPlayback();
recorder = new MediaRecorder();
recorder.SetVideoSource(VideoSource.Camera);
recorder.SetAudioSource(AudioSource.Mic);
recorder.SetOutputFormat(OutputFormat.Default);
// get suppored video sizes
var camera = Android.Hardware.Camera.Open();
var cameraParameters = camera.GetParameters();
var supportedSizes = cameraParameters.SupportedVideoSizes;
// set video size to a suppored size
// comment this out and it works
recorder.SetVideoSize(supportedSizes[0].Width, supportedSizes[0].Height);
recorder.SetVideoEncoder(VideoEncoder.Default);
recorder.SetAudioEncoder(AudioEncoder.Default);
recorder.SetOutputFile(_path);
recorder.SetPreviewDisplay(_video.Holder.Surface);
recorder.Prepare();
recorder.Start(); // fails with IllegalStateException
}
catch (Exception ex)
{
// IllegalStateException thrown
// error message is "start failed"
}
}
根据API specification,我认为我使用正确,但我不明白为什么我无法设置视频大小。
我做错了吗?有什么我想念的吗?我应该采取不同的做法吗?
【问题讨论】:
标签: android xamarin xamarin.android android-camera