我正在尝试开发一个UWP应用,我需要通过网络摄像头录制视频。我在这里关注了微软教程,但问题是我一次又一次地听到错误并且录音不起作用。
错误
“此对象需要在请求的操作之前初始化 可以进行。\ r \ n这个对象需要在之前初始化 请求的操作可以进行。“
这是我的代码:
int counter = 1;
var myVideos = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Videos);
StorageFile file = await myVideos.SaveFolder.CreateFileAsync("survillance "+DateTime.Now.ToString("dd-MM-yyyy")+"_"+counter+".wmv", CreationCollisionOption.GenerateUniqueName);
try
{
MediaEncodingProfile recordProfile = null;
recordProfile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Auto);
_mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync(recordProfile,file);
await _mediaRecording.StartAsync();
status.Text = "Video recording in progress...";
}
catch (Exception ex)
{
status.Text = "Failed to Capture...";
var msg = new MessageDialog(ex.Message, "Capturing Error").ShowAsync();
}
请帮我弄清问题。感谢
答案 0 :(得分:0)
在开始捕获之前,您忘了拨打MediaCapture.InitializeAsync()。
MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
_mediaCapture = new MediaCapture();
_mediaCapture.InitializeAsync();
_mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync(recordProfile,file);
await _mediaRecording.StartAsync();