×

Discussion Board

Results 1 to 13 of 13

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Exclamation PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Hello everybody.

    I am pretty new to the WP platform, and am currently researching some of the APIs I will need for my next application.

    Using the article called "How to create a base camera app for Windows Phone" as a starting point, I wrote a very simple application that is supposed to capture a single picture using the front facing camera, which works as expected on the emulator, but fails when I run it on a physical device. However, it runs fine on the device if I use the back camera.

    The problem I am experiencing is that after calling the CaptureImage() method on the PhotoCamera object, the CaptureStarted event fires as expected, but after that, the application hangs and no other event is fired (i.e. the capture never completes).

    If I stop the application and start it again, I get a System.InvalidOperationException when calling the CaptureImage() method (with the following exception message: "You cannot use this instance until it is fully initialized"). At this point the only way to get the PhotoCamera object to initialize correctly is restarting the device.

    The code is very simple, but I'm including it here so anyone can take a look at it (relevant portions only):

    Code:
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                Debugger.Log(1, "Info", "\nOnNavigatedTo Event fired\n");
                try{
                        cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
    
                        cam.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(cam_Initialized);
                        cam.CaptureStarted += new EventHandler(cam_CaptureStarted);
                        cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_CaptureCompleted);
                        cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
                        cam.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(cam_CaptureThumbnailAvailable);
                        viewfinderBrush.SetSource(cam);
                        Debugger.Log(1, "Info", "\nSource set\n");
                    }
                    catch (Exception excep)
                    {
                        Debugger.Log(1, "Info", "\nException in OnNavigatedTo: " + excep.Message + "\n");
                    }
            }
            private void ShutterButton_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    cam.CaptureImage();
                    Debugger.Log(1, "Info", "CaptureImage method called\n");
                }
                catch (Exception ex)
                {
                    Debugger.Log(1, "Info", "CaptureImage exception: " + ex.Message + "\n");
                }
            }
    
            void cam_Initialized(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e)
            {
                if (e.Succeeded)
                {
                        Debugger.Log(1, "Info", "Camera initialized\n");
                }
                else
                {
                    Debugger.Log(1, "Info", "\nFailed to initialize. Message: " + e.Exception.Message + ":** " + e.Exception.StackTrace + "\n");
                }
            }
    
            void cam_CaptureStarted(object sender, EventArgs e)
            {
                Debugger.Log(1, "Info", "CaptureStarted event fired\n");
            }
    The other event handlers only include debug messages, so I did not include them here.

    When I run the application on the emulator (or on the device, but using the back camera), I get the following debug messages sequence, as expected:

    OnNavigatedTo Event fired
    Source set
    Camera initialized
    CaptureImage method called
    CaptureStarted event fired
    CaptureThumbnailAvailable event fired
    CaptureImageAvailable event fired
    CaptureCompleted event fired

    But when I run it on the device (front camera), I just get these (and then the App hangs):

    OnNavigatedTo Event fired
    Source set
    Camera initialized
    CaptureImage method called
    CaptureStarted event fired

    So, my questions would be:

    1. Am I doing something wrong, or missing something? (if so, why the App runs without issues on the emulator, or when using the back camera on the device?)
    2. Is there something additional I can do to debug the issue? (I don't seem to find any additional way to debug the problem at a lower level)
    3. Has someone else experimented this problem? If so, how did you solved it or worked around it?


    Also, it would be really nice if someone else could try this operation on another 820 developer device. I'm starting to think that this is some kind of device-specific issue, maybe related to the firmware or something similar.

    ================================
    UPDATE - 13/02/2013
    ================================

    I modified the application to use the PhotoCaptureDevice class instead of PhotoCamera, as described in article "Advanced photo capture for Windows Phone 8", but the results are basically the same. After I call the capture sequence's StartCaptureAsync() method, the application hangs. As before, it only happens on the device when the front facing camera is being used.
    ================================

    ================================
    UPDATE - 14/02/2013
    ================================

    I tried the same code on a Lumia 920 (through RDA) and it works without any issues, so this is probably not a flaw in the code, as I suspected. If anyone has the time, please test it on a 820 dev device.
    ================================

    I'm not sure if this is somehow related, but I tested the Microsoft's BLINK App a few days ago, and when I switch to the front facing camera in that App, my phone restarts. I asked a few friends about this on twitter , and one of them told me that she saw a similar behaviour on a 825 device.

    I'm using a Lumia 820 developer device (OS versión: 8.0.9903.10. firmware revisión: 1232.2110.1244.3002).

    If any additional details are needed, just let me know.

    Thanks for your time, and for any answers, comments or suggestions you can provide.
    Last edited by cadlg; 2013-02-14 at 07:05. Reason: Additional options tried
    -CarlosDL

  2. #2
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    I'm planning to start playing with the native camera APIs today, to see if it makes a difference. I've tested some camera apps and most of them work even when using the front camera, so even if this is a device-specific issue, there must be a way to make it work. The front facing camera is key for my next project, so I really need to be able to test it on my device. If the native APIs don't work, I will open a support ticket, and let you know the results.

    Any help, comments or suggestions are very welcome.
    -CarlosDL

  3. #3
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    I'll try test this tomorrow morning on a device and give you a feedback.

  4. #4
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Hello I've just tryed your code on a 820, and yes I get the same error as you, the app works first launch and when you take a pic it hangs, and it won't work after at all.
    I uninstalled the app and tryed to deploy it on the device again but got an error as if the frontfacing camera is still used, then I tryed to open an app where the frontfacing camera works (Skype), got a black screen and the phone rebooted.

  5. #5
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Quote Originally Posted by Loukt View Post
    Hello I've just tryed your code on a 820, and yes I get the same error as you, the app works first launch and when you take a pic it hangs, and it won't work after at all.
    I uninstalled the app and tryed to deploy it on the device again but got an error as if the frontfacing camera is still used, then I tryed to open an app where the frontfacing camera works (Skype), got a black screen and the phone rebooted.
    Thanks for the feedback, Loukt, I really appreciate it.

    Does somebody know if there is a place where we can report this to the appropriate Nokia engineers. I was planning to submit a support ticket, but if this is something that fails on every 820, maybe that is not the appropriate action to take.

    Any suggestions?
    -CarlosDL

  6. #6
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    481

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Hi.
    This code works for me with 920 and 820(dev version):
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using testcamera.Resources;
    using System.Diagnostics;
    using Microsoft.Devices;
    using System.Windows.Media;
    
    namespace testcamera
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                // Sample code to localize the ApplicationBar
                //BuildLocalizedApplicationBar();
            }
            Microsoft.Devices.PhotoCamera cam = null;
            VideoBrush viewfinderBrush;
    
            protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                Debugger.Log(1, "Info", "\nOnNavigatedTo Event fired\n");
                try
                {
                    viewfinderBrush = new VideoBrush();
                    canvas.Background = viewfinderBrush;
                    CameraButtons.ShutterKeyPressed +=ShutterButton_Click;
    
                    cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
    
                    cam.Initialized += cam_Initialized;
    
                    cam.CaptureStarted += (s,ee)=>{ Debugger.Log(1, "Info", "CaptureStarted event fired\n");};
                    cam.CaptureCompleted += (s,ee)=>{ Debugger.Log(1, "Info", "CaptureCompleted event fired\n");};
                    cam.CaptureImageAvailable +=  (s,ee)=>{ Debugger.Log(1, "Info", "CaptureImageAvailable event fired\n");};
                    cam.CaptureThumbnailAvailable += (s, ee) => { Debugger.Log(1, "Info", "CaptureThumbnailAvailable event fired\n"); };
                    viewfinderBrush.SetSource(cam);
                    Debugger.Log(1, "Info", "\nSource set\n");
                }
                catch (Exception excep)
                {
                    Debugger.Log(1, "Info", "\nException in OnNavigatedTo: " + excep.Message + "\n");
                }
            }
    
            private void ShutterButton_Click(object sender, EventArgs e)
            {
                try
                {
                    cam.CaptureImage();
                    Debugger.Log(1, "Info", "CaptureImage method called\n");
                }
                catch (Exception ex)
                {
                    Debugger.Log(1, "Info", "CaptureImage exception: " + ex.Message + "\n");
                }
            }
            void cam_Initialized(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e)
            {
                if (e.Succeeded)
                {
                    Debugger.Log(1, "Info", "Camera initialized\n");
                }
                else
                {
                    Debugger.Log(1, "Info", "\nFailed to initialize. Message: " + e.Exception.Message + ":** " + e.Exception.StackTrace + "\n");
                }
            }
        }
    }
    Code:
    <phone:PhoneApplicationPage
        x:Class="testcamera.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True">
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Canvas x:Name="canvas"></Canvas>
        </Grid>
    
    </phone:PhoneApplicationPage>
    why your ShutterButton_Click use a RoutedEventArgs ?

  7. #7
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Thanks yan_

    Quote Originally Posted by yan_ View Post
    why your ShutterButton_Click use a RoutedEventArgs ?
    Not exactly sure why. That is how the event handler is automatically created when you double-click on the button.

    I tested your code, but it fails on my device. Can you share the OS version and firmware revision running on your phone (the 820) ?
    -CarlosDL

  8. #8
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    481

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    I've installed this firmware :


    It's normally the last firmware for french Orange provider
    Last edited by yan_; 2013-02-18 at 20:29.

  9. #9
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Thanks yan_.

    There are differences in OS, firmware and transmision software versions. In all 3 cases your device appears to be running more recent versions. That could be the reason, but unfortunately nothing shows up when I check for updates on my phone.

    I have not had the time to try the native camera APIs yet, but I hope to be able to do it next week (hopefully I can write a Wiki article on that topic when I finish testing).

    Any additional suggestions are still very welcome.
    -CarlosDL

  10. #10
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Today's update, which included updates from Microsoft and Nokia solved the issue on my 820.

    Thanks everybody.
    -CarlosDL

  11. #11
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    481

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    how have you solved your problem?

  12. #12
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820

    Quote Originally Posted by yan_ View Post
    how have you solved your problem?
    The last WP8 Update solved the problem (Version : 8.0.10211.204).
    We still don't know what causes it, but it's solved.

Similar Threads

  1. Camera captureImage crash (Symbian)
    By pixsta in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2012-04-06, 12:57
  2. Using front camera with camera wrapper
    By juannoguera in forum Symbian Media (Closed)
    Replies: 7
    Last Post: 2010-08-25, 13:31
  3. Change Camera::CaptureImage() Resolution
    By neelesh_a1 in forum Symbian
    Replies: 2
    Last Post: 2010-01-27, 21:20
  4. How to use Front Camera
    By kartikbansal in forum Mobile Java Media (Graphics & Sounds)
    Replies: 15
    Last Post: 2008-12-10, 10:01
  5. Replies: 3
    Last Post: 2008-05-05, 16:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×