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 "[URL="http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202956%28v=vs.105%29.aspx"]How to create a base camera app for Windows Phone[/URL]" 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");
}
[/CODE]
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:
[INDENT]OnNavigatedTo Event fired
Source set
Camera initialized
CaptureImage method called
CaptureStarted event fired
CaptureThumbnailAvailable event fired
CaptureImageAvailable event fired
CaptureCompleted event fired[/INDENT]
But when I run it on the device (front camera), I just get these (and then the App hangs):
[INDENT]OnNavigatedTo Event fired
Source set
Camera initialized
CaptureImage method called
CaptureStarted event fired[/INDENT]
So, my questions would be:
[LIST=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?)[*]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)[*]Has someone else experimented this problem? If so, how did you solved it or worked around it?[/LIST]
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.
[B]================================
UPDATE - 13/02/2013
================================[/B]
I modified the application to use the PhotoCaptureDevice class instead of PhotoCamera, as described in article "[URL="http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662940%28v=vs.105%29.aspx"]Advanced photo capture for Windows Phone 8[/URL]", 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.
[B]================================[/B]
[B]================================
UPDATE - 14/02/2013
================================[/B]
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.
[B]================================[/B]
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.
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.
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.
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.
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
[QUOTE=Loukt;911376]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.[/QUOTE]
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?
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]
[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>[/CODE]
why your [B]ShutterButton_Click [/B]use a [B]RoutedEventArgs [/B]?
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
Thanks yan_
[QUOTE=yan_;911404]
why your [B]ShutterButton_Click [/B]use a [B]RoutedEventArgs [/B]?[/QUOTE]
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) ?
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
I've installed this firmware :
[IMG]http://img14.imageshack.us/img14/5729/wpss201302180001.jpg[/IMG]
It's normally the last firmware for french Orange provider
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).
[B]Any additional suggestions are still very welcome.[/B]
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.
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
how have you solved your problem?
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
[QUOTE=yan_;911780]how have you solved your problem?[/QUOTE]
The last WP8 Update solved the problem ([B]Version [/B]: 8.0.10211.204).
We still don't know what causes it, but it's solved.
Re: PhotoCamera.CaptureImage() fails with front facing camera on Lumia820
[QUOTE=Loukt;911786]The last WP8 Update solved the problem ([B]Version [/B]: 8.0.10211.204).
We still don't know what causes it, but it's solved.[/QUOTE]
Yep, that's right.
I spent some days experimenting with the native APIs, but the official documentation on that topic is really bad, and the solution for my problem came (through the aforementioned update) before I could make those APIs work. Unfortunately my time is very scarce, so I will have to move away from the native APIs and continue working on my project using the managed ones.