locked
How to tell whether video preview is working?

    Question

  • An app shows video preview with code essentially the same as in the MSDN document:

    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. However, sometimes the video does not show. When this happens, myCaptureElement.ActualWidth and myCaptureElement.ActualHeight still return the correct values. This probably means at least something is working. In this case, how can the code tell what my eyes can see - the video is not showing?


    Hong

    Monday, February 16, 2015 12:37 PM

Answers

  • Hi Hong,

    Based on my knowledge, your problem may related to the dispose of the MediaCapture object. Forget to dispose it when app suspends will result in a negative user experience for your app.

    About your question, I’ve not seen such property in MediaCapture class, so it’s recommend to create a Boolean that indicate whether the app is currently previewing video. You need to maintain this object when start or stop preview. You can find more information from this page. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868171.aspx. See Step 5 section.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, February 24, 2015 3:21 AM
    Moderator

All replies

  • What is "myCaptureElement"? Is it possible for you to post the whole code for the Preview Page (XAML & C#)?
    Monday, February 16, 2015 3:35 PM
  • Thanks for the response.

    myCaptureElement is CaptureElement. The entire code is in the aforementioned MSDN document

    The Xaml code is the following:

    <CaptureElement x:Name="myCaptureElement" 
                    HorizontalAlignment="Left"         
                    Width="320" Height="240" />

    Please forgiving me for borrowing MSDN code here.  My actual code is effectively the same, but the relevant lines are scattered.  I don't want to post the code with 90% of unrelated contents.

    Actually, my question is a kind of general. Regardless of how preview is started, is there a way to determine whether CaptureElement is actually showing video?


    Hong

    Monday, February 16, 2015 3:48 PM
  • Hi Hong,

    Based on my knowledge, your problem may related to the dispose of the MediaCapture object. Forget to dispose it when app suspends will result in a negative user experience for your app.

    About your question, I’ve not seen such property in MediaCapture class, so it’s recommend to create a Boolean that indicate whether the app is currently previewing video. You need to maintain this object when start or stop preview. You can find more information from this page. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868171.aspx. See Step 5 section.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, February 24, 2015 3:21 AM
    Moderator
  • Thank you for the tips, Herro.

    I assume there is no direct way to tell whether video preview is actually working.

    I have tried to clean MediaCapture and CaptureElement when the app navigates to other pages.  I will examine the code thoroughly again and enhance the disposing mechanism based on your tips.  I will report back if the issue persists. 


    Hong


    Wednesday, February 25, 2015 11:59 AM