locked
Exception "Incorrect funtion" when using front camera

    Question

  • I have an app where I use a camera. The back camera works just fine, but the front camera causes an exception:

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

       at Speurtochie.MainPage.<ShowViewFinder>d__88.MoveNext()}

        Data: {System.Collections.ListDictionaryInternal}

        HelpLink: null

        HResult: -2147024895

        InnerException: null

        Message: "Incorrect function.\r\n\r\nIncorrect function.\r\n"

        Source: ""

        StackTrace: "   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at Speurtochie.MainPage.<ShowViewFinder>d__88.MoveNext()"

    This exception occurs in this code:

    await takePhotoManager.InitializeAsync(new MediaCaptureInitializationSettings
    	{
    		StreamingCaptureMode = StreamingCaptureMode.Video,
    		PhotoCaptureSource = PhotoCaptureSource.Photo,
    		AudioDeviceId = string.Empty,
    		VideoDeviceId = Back ? BackCameraID : FrontCameraID
    	});

    Every time a try to use the front camera, I get the id earlier (see the code below), the app crashes when InitializeAsync is called.

    private async Task<bool> GetCameras()
    {
    	DeviceInformationCollection dic = await DeviceInformation.FindAllAsync();
    	foreach (DeviceInformation di in dic)
    	{
    		if (di.EnclosureLocation != null && di.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front)
    		{
    			FrontCameraID = di.Id;
    			bttnSwitchCamera.Visibility = Visibility.Visible;
    		}
    		if (di.EnclosureLocation != null && di.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back)
    		{
    			BackCameraID = di.Id;
    		}
    		if (FrontCameraID != "" && BackCameraID != "")
    		{
    			break;
    		}
    	}
    	return true;
    }

    I checked, I really get the Front camera Id and the back camera Id with the code above.

    I have a Lumia 930 to test with, and the front camera works just fine.


    Friday, April 17, 2015 8:51 PM

Answers

  • I figured it out. I forgot to add DeviceClass.VideoCapture in DeviceInformation.FindAllAsync()

    So the first "front" device it returned was the front microphone and not the front camera.

    I overlooked  one simple line of code and as a result I was debugging for hours to find out what was wrong and even started a topic here. A developers life isn't easy ;)

    Tuesday, April 21, 2015 5:42 AM

All replies

  • Hello,

    This is likely due to the fact that either PhotoCaptureSource.Photo is not supported for the front camera.

    I hope this helps,

    James


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

    Saturday, April 18, 2015 12:46 AM
    Moderator
  • Even if I try PhotoCaptureSource.Auto or PhotoCaptureSource.VidoePreview or leave that line out, the front camera doesn't work.

    Every single example on the internet I found for the Front camera uses the code I use, but somehow it won't function.

    Any other app which uses the front camera functions properly, so I do something wrong. But what?

    Saturday, April 18, 2015 5:48 AM
  • Hello,

    That is really strange. Does the MSDN sample work for you?

    Media capture using capture device sample

    -James


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

    Monday, April 20, 2015 11:09 PM
    Moderator
  • I figured it out. I forgot to add DeviceClass.VideoCapture in DeviceInformation.FindAllAsync()

    So the first "front" device it returned was the front microphone and not the front camera.

    I overlooked  one simple line of code and as a result I was debugging for hours to find out what was wrong and even started a topic here. A developers life isn't easy ;)

    Tuesday, April 21, 2015 5:42 AM