locked
Capture Element not showing preview Second time.

    Question

  • I am developing an app in which I need to take a picture using camera. So i have used capture Element and button to Take a photo but when I want to close the mediacapture object without taking a photo and then again try to capture a photo it does not start previewing. My Code is 

            public MediaCapture _mediaCapture;
            private async Task InitializeQrCode()
            {
                // Find all available webcams
                DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
    
                // Get the proper webcam (default one)
                DeviceInformation backWebcam = (from webcam in webcamList
                                                where webcam.IsEnabled
                                                select webcam).FirstOrDefault();
    
                // Initializing MediaCapture
                _mediaCapture = new MediaCapture();
                await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = backWebcam.Id,
                    AudioDeviceId = "",
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                });
    
                // Adjust camera rotation for Phone
                _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                _mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
    
                // Set the source of CaptureElement to MediaCapture
                captureElement.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();
            }
    

    Code I use to close the _mediacapture is 

    await _mediaCapture.StopPreviewAsync();
                                _mediaCapture.Dispose();

    If I go to another page and try then it works properly. I could not resolve this. Can somebody help?

    Thursday, May 07, 2015 12:25 PM

Answers

  • Hello,

    Unfortunately I am not able to reproduce this issue based on the code you provided. I have created a small sample based on your code.

    You can find it here:

    http://1drv.ms/1ETuWpQ

    Please give it a try and let me know if it works for you.

    Thanks,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by RohitrkKUmar Friday, May 08, 2015 12:12 PM
    Thursday, May 07, 2015 10:31 PM
    Moderator

All replies

  • Hello,

    Unfortunately I am not able to reproduce this issue based on the code you provided. I have created a small sample based on your code.

    You can find it here:

    http://1drv.ms/1ETuWpQ

    Please give it a try and let me know if it works for you.

    Thanks,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Marked as answer by RohitrkKUmar Friday, May 08, 2015 12:12 PM
    Thursday, May 07, 2015 10:31 PM
    Moderator
  • Thanks for your answer. it worked for me.
    Friday, May 08, 2015 12:13 PM