Phone restarts when Camera is recording in flyout and back button is pressed. RRS feed

  • Question

  • I am developing an app in which I have some tabs which are shown on every page. In one of screens I need to click a picture and I can't hide the tabs. So I created a flyout and put a captureElement and buttons to capture image in it. But when the camera is recording and hardware back button is pressed then the phone freezes and restarts. I could not find the reason. Can anybody help? 

    My Code is

    <Grid Grid.Row="1" x:Name="ContentRoot">
                <TextBlock Text="Capture Image" FontSize="26" Tapped="TextBlock_Tapped" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <Flyout Placement="Full">
                                <CaptureElement Name="captureElement" Stretch="UniformToFill" HorizontalAlignment="Stretch"/>
                                <Button Content="Capture" Tapped="Button_Tapped"/>
                                <Button Content="Save" Tapped="Button_Tapped_1"/>

    private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
                captureElement.Width = 620;
                captureElement.Height = 800;
                var element = sender as FrameworkElement;
                if (element != null)

            MediaCapture _capture;
            async private void Button_Tapped(object sender, TappedRoutedEventArgs e)
                    _capture = new MediaCapture();
                    await _capture.InitializeAsync();
                catch { } 
                captureElement.Source = _capture;
                await _capture.StartPreviewAsync();

            async private void Button_Tapped_1(object sender, TappedRoutedEventArgs e)
                StorageFile sfa = await KnownFolders.CameraRoll.CreateFileAsync("Demo.jpg", CreationCollisionOption.GenerateUniqueName);
                StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync("Demo.jpg", CreationCollisionOption.GenerateUniqueName);
                await _capture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), sfa);
                await _capture.StopPreviewAsync();

    Friday, April 10, 2015 7:30 AM

All replies

  • It sounds like you're running into some kind of driver bug. Are you specifically handling the back button press?  If not, can you listen for that and see if the problem still reproduces?

    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.

    Friday, April 10, 2015 2:50 PM
  • Sorry for replying late.

    I tried to control the backpress event and it did handle the system restart but when next time the code is called then CaptureElement does not start streaming. Is this expected behavior?

    Tuesday, April 21, 2015 7:42 AM