empty (0km) file or start failed on some devices

I had this problem with my app (ScareApp) that uses the front facing camera to record video. I "think" I've finally resolved the issue, so thought I would post it here for any developers that run into the same thing....

Basically.. The android MediaRecorder allows you to define the Video and Audio Encoder, and according to the docs, DEFAULT can be used for each. However, this refers to the main camera's settings, which is often a far higher spec than the front facing camera. DEFAULT on the Droid Razr for example, selects an encoding (MPEG_4_SP) that isn't available for the Front facing camera, and this results in an empty (0kb) file being produced (or on some other devices a Camera 100 - start failed error).

My other option was to use the CameraProfile.get method to lookup what the HIGH_QUALITY settings, but again, this by default uses the main camera. To get around this, you can set the ID of the front facing camera by using

CameraProfile.get(<CameraID>, CamcorderProfile.QUALITY_HIGH);

My current work around is as follows:

CamcorderProfile profile = CamcorderProfile.get(FrontFacingCameraId, CamcorderProfile.QUALITY_HIGH);
if(profile != null) {
    _recorder.setAudioEncoder(profile.audioCodec);      
    _recorder.setVideoEncoder(profile.videoCodec);
}else {
    //default to basic H263 and AMR_NB if profile not found
    _recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);       
    _recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
}

Or alternatively, you can skip setting the Encoders, and just use

_recorder.setProfile(profile);

But as my app allows the user to select the resolution, I need to set the encoder's.

Hopefully this will help someone and save the time and hassle it has caused me!

Cheers, Mark

链接地址: http://www.djcxy.com/p/5258.html

上一篇: Android MediaRecorder会导致强制停止错误

下一篇: 空的(0km)文件或在某些设备上启动失败