Mediarecorder start failed - 19 error when running start() for MediaRecorder を取得しています。これは、次のコードでフロント カメラからキャプチャするようにカメラを設定しようとしている場合にのみ発生します。
private Camera openFrontFacingCamera()
{
int cameraCount = 0;
Camera cam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) {
Camera.getCameraInfo( camIdx, cameraInfo );
if ( cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) {
try {
cam = Camera.open( camIdx );
} catch (RuntimeException e) {
Log.e("my tag", "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return cam;
}
これは私の startRecording 関数です:
public void startRecording() throws IOException
{
mCamera = openFrontFacingCamera();
mrec = new MediaRecorder(); // Works well
mCamera.unlock();
mrec.setCamera(mCamera);
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mrec.setPreviewDisplay(surfaceHolder.getSurface());
//Toast.makeText(this,Integer.toString(Date),Toast.LENGTH_SHORT).show();
String time = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/" + getString(R.string.app_name)+ "/" + DateFormat.getDateTimeInstance().format(new Date()).trim() + ".3gp";
File directory = new File(time).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
mrec.setOutputFile(time);
mrec.prepare();
mrec.start();
}
とエラー:
10-04 10:52:29.488 15546-15546/com.didi.***** E/AndroidRuntime: java.lang.RuntimeException: start failed.
10-04 10:52:29.488 15546-15546/com.didi.***** E/AndroidRuntime:at android.media.MediaRecorder.start(Native Method)