Okay so I have spent all day trying to fix this problem, I have read every article on StackOverflow relating to the error code and other similar issues but nothing seems to make any difference.
I have two different code bases with the same problem.
The first one is code copied straight from developer.android.com here:
The second one is this code:
Both work fine with the normal rear camera, but as soon as I try to use the front facing camera I get the error.
This happens on the following devices:
c = Camera.open(frontFacingCameraID); // attempt to get a Camera instance
Camera.Parameters params = c.getParameters();
Okay so I finally have it working sort of.
The issue seems to definately relate to Profile Settings and in particular Frame Rate.
On the Nexus S, my main test device if I probe the Camera.Parameters I get:
For the Rear Camera:
15 FPS to 30 FPS, fair enough.
For the Front Facing Camera:
7.5 FPS to 30 FPS, okay.
Then I check the Profiles I am trying to use,:
audioCodec: AMR_NB audioSampleRate: 8000
Clearly, the High Quality Profile is meant for the Rear Camera, seeing as the front facing is only 640x480. But they both state 30 FPS.
Heres the weirdness.
If I set ANY frame rate for the rear facing camera, no matter what profile, it crashes with the dreaded: -19 error
Thats not a big deal coz I dont care about the rear camera but it is weird, considering the profiles are defaulting to 30 and the Params say they accept 15-30. But no int value iv tried has worked. If I ommit the setVideoFrameRate its fine.
Anyway, moving onto the Front Facing Camera.
So, if I use the QUALITY_LOW profile AND set the frame-rate to 15 or lower, it magically works.
Infact any value, 1 - 15 works. Which seems weird.
So heres the connundrum, I can probably probe for resolution and select an appropriate res for most cameras, although im also fairly confident almost all front-facing cameras at minimum VGA 640x480.
But, what about the frame rate? In the case of the Nexus S, I don't see any way I could determine the value of 15 or lower without just guessing? Should I aim to always use the LOWEST frame-rate that is returned by the Camera?
I took at look at the Galaxy Nexus and it has 3 frame rate ranges, the first one is 15 - 15 and the second is 15 - 30. Its low quality profile is similar albiet higher resolution. If I use low profile on Galaxy Nexus it seems to work fine.
With the Nexus 7, I cant probe the CamcorderProfile's I keep getting null pointers, which is weird. It says it supports 4 FPS - 60 FPS. If I choose QUALITY_LOW which youd think should work, it crashes, and I cant find a frame rate it will work with. Although the error relates to setProfile, so I think the issue is with the built in profile. Surely the point of Android API is that its consistent, this is a flag ship device and the FF camera is there for Video Conferencing isnt it?????
So, while I have it working on two of the devices using manual custom settings for each, I can't see a clear way of making it work across multiple devices through code.
It seems that the Nexus S does not behave the way it promises to with regards to setting the FPS as per its Camera.getParameters().getSupportedPreviewFpsRange()
Im all happy for it to use Auto FPS settings but apparently it wont with the FF camera so what am I supposed to do? I have to explicitly set the FPS on the Nexus S and in this case to anything from 1 to 15 FPS, despite the Camera telling me it handles 7.5 - 30 FPS.
Seems like the promise of the setProfile fixing all the issues in 2.x wasnt entirely true.
I can understand if your writing the Camera App for a particular ROM you just customize it to that particular hardware, which might explain why people seem to always have buggy camera apps on custom roms. BUT..... how do downloadable video recording apps work? Are they custom to each device?
Is this why theres no Facebook Poke and Twitter Vine on Android yet???? :P
Shit Google, wtf is with your Camera API?
Does ANYONE know the best practises way to determine resolution and frame-rate for ALL API 15+ compatible devices?
Is that even possible, or am I going to be writing custom code on each device I test and then just roll the dice on the rest?
Or is the Nexus S and the Nexus 7 just freak accidents?