The preview code of an app is essentially the same as the example in
the MSDN document for CaptureElement:
async void ShowPreview(object sender, RoutedEventArgs e)
{
if (mediaCaptureMgr == null)
{
// Using Windows.Media.Capture.MediaCapture APIs
// to stream from webcam
mediaCaptureMgr = new MediaCapture();
await mediaCaptureMgr.InitializeAsync();
myCaptureElement.Source = mediaCaptureMgr;
await mediaCaptureMgr.StartPreviewAsync();
}
}
It works most of the time, but fails occasionally. By "fails", I mean that I do not see the preview, but no exception is generated. I am wondering if there is a way to determine whether the preview is working in the code. Many of the async
function do not return anything, so I do not know what to check to ensure they return with success.
Hong