This project is read-only.

Disposing and restarting the CameraCaptureControl

Apr 12, 2013 at 3:53 PM
Edited Apr 12, 2013 at 3:55 PM
I am trying to dispose all elements in CameraCaptureControl and restart it again on CameraFailed event. Here is the code i am using currently, (for both video and photo capturing)
async public Task RestartCamera()
        {
            try
            {

// for Video and audio recording
                if (StreamingCaptureMode == Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo)
                {
                    if (_recordingAnimation != null)
                    {
                        _recordingAnimation.Stop();
                    }
                    if (_recordingIndicator != null)
                    {
                        _recordingIndicator.Visibility = Visibility.Collapsed;
                    }
                    if (MediaCapture != null)
                    {
#pragma warning disable 4014
                        if (_internalState == CameraCaptureControlStates.Recording)
                        {
                            _mediaCapture.StopRecordAsync();
                        }
                        _mediaCapture.StopPreviewAsync();
#pragma warning restore 4014
                    }
                }
                else
                {

// for taking photo
                    if (MediaCapture != null)
                    {
#pragma warning disable 4014
                        _mediaCapture.StopPreviewAsync();
#pragma warning restore 4014
                    }
                }
            }
            catch (Exception ex)
            {
            }
and i am using this function in CameraFailed event like below,
async private void CameraCaptureControl_CameraFailed(object sender, MediaCaptureFailedEventArgs e)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {
                    await CameraCaptureControl.RestartCamera();
                    await CameraCaptureControl.ShowAsync();
                }
                catch (Exception ex)
                {
                }
            });
        }
this method stops the CameraCaptureControl but doesn't start the preview again (ShowAsync).

what am i doing wrong..? Is there any best way available to get this thing done.?
Apr 12, 2013 at 4:19 PM
Sorry, I don't know, but feel free to share once you figure this out.
Oct 16, 2014 at 3:50 PM
Where are you re-initializing the camera? All I see is
_mediaCapture.StopPreviewAsync();
and no
_mediaCapture.StartPreviewAsync();