简体   繁体   English

UWP Media Capture无法通过WebCam录制视频

[英]UWP Media Capture Not Recording Video through WebCam

I am trying to develop a UWP app where I need to record video via webcam. 我正在尝试开发一个UWP应用,我需要通过网络摄像头录制视频。 I have followed microsoft tutorial about it here but the problem is I am getting following error again and again and recording does not work. 我在这里遵循了有关它的Microsoft教程,但问题是我一次又一次地跟随错误,并且记录无法正常工作。

Error 错误

"This object needs to be initialized before the requested operation can be carried out.\\r\\nThis object needs to be initialized before the requested operation can be carried out." “必须先初始化此对象,然后才能执行请求的操作。\\ r \\ n需要先初始化此对象,然后才能执行请求的操作。”

Here is my code: 这是我的代码:

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();
                }

Please help me in figuring out the problem. 请帮助我解决问题。 Thanks 谢谢

You forgot to call MediaCapture.InitializeAsync() before starting the capture. 您忘了在开始捕获之前调用MediaCapture.InitializeAsync()

MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

_mediaCapture   = new MediaCapture();
_mediaCapture.InitializeAsync();

_mediaRecording = await _mediaCapture.PrepareLowLagRecordToStorageFileAsync(recordProfile,file);
await _mediaRecording.StartAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM