How to detect camera preview is not working RRS feed

  • Question

  • 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.   


    Friday, May 30, 2014 11:37 AM

All replies

  • This is a tough scenario. If it fails only occasionally, I doubt that there's anything wrong with the code itself. It sounds like there's a non-UI thread that is getting an exception which does not bubble up and can't be caught.  Can you post a reproduction app so we can try to test this ourselves?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 2, 2014 7:36 PM