So I have been working on a recording module for a larger application.
It’s fully functional on most devices, but there is one batch of phones that simply refuse recording.
Whenever I start the recording using the MediaRecorder, LogCat will graciously tell me that MediaRecorder failed to start, resulting in error code -12.
I have been scouring the internets for most of the day looking for an explanation to these error codes. So far I have been unlucky. Hence I turn myself to the rest of the developer community.
MediaRecorder start failed -12
More than one question has already been asked about those error codes and more specifically 16, 19, 22 and one ridiculously large number 2147483648, but this information has proven to be useless in my case.
Does anyone know where I can find a reliable list of MediaRecorder error codes including the meaning of these? Or even better, explain to me what the almighty Android oracle is trying to signal me?
Thanks in advance
My previous answer was not complete.
After more tinkering I found out that many devices can be very sensitive to settings you would think of being default for most devices, but in fact there are many devices that do not behave the way you would expect and they will crash giving you many different error codes that you will not be able to find on the internet. These error codes range from -12, -19, -21 to -100 etc. and most of these error codes can be resolved by using the tips below. I will give a short list of findings below:
The HTC ChaCha running API 10 does not record using the H264 encoder. I got it to work using MP4 and/or H263, however the video still came out totally distorted. The solution to that was setting the camera preview size to 640*480 instead of using google’s own “optimal preview” method which returns 576*432. By setting exceptions for this model, I was able to make it record perfectly.
The Galaxy Y running API 10 crashes when trying to record using H264. Made an exception for this one to use MP4 encoder. Fixed it.
The Galaxy Ace running API 10 crashes when trying to record using MP4 returning error code -12. Adding an exception using the H264 encoder for this device model fixes the problem.
The Desire Z running API 10 crashes when trying to record using MP4 encoder. Gave me an error -100 (Media server died). Using H264 fixes the problem.
I bet I will run into more models being a metaphorical pain in the crack and when I do, I will add them to the list.
To sum up; if you run into these annoying, almost unexplainable error codes, have a look at the MediaRecorder parameters. I advice against using the CamcorderProfile class for any API below 11, since many of these models crash while using a high quality instance of this.
If your recorder video file shows weird green colours, semi-diagonal lines running through your screen, etc, try to set the preview size to match the recorder video size.