I am trying to record a video stream from my Galaxy tab to a server. according to this guide i should do something like this:
frontCamera = getFrontCamera(); if((socket!= null)&&(frontCamera!=null)) { try { frontCamera.setPreviewDisplay(cameraPreview.getHolder()); } catch (IOException e1) { // TODO Auto-generated catch block Log.e("","",e1); } frontCamera.startPreview(); recorder = new MediaRecorder(); frontCamera.unlock(); recorder.setCamera(frontCamera); recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setProfile(CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH)); pfd = ParcelFileDescriptor.fromSocket(socket); recorder.setOutputFile(pfd.getFileDescriptor()); recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface()); try { recorder.prepare(); recorder.start(); } catch (IllegalStateException e) { // TODO Auto-generated catch block Log.e("","",e); } catch (IOException e) { // TODO Auto-generated catch block Log.e("","",e); }
but everything crashes in step recorder.start();
with a strange mistake
02-01 19:03:39.265: E/MediaRecorder(11922): start failed: -19
What does it mean and what should I do to start the recorder?
UPD: The problem is due to my getFrontCamera method. when i replace it with camera.open () everything works correctly.
protected Camera getFrontCamera() { Camera.CameraInfo inf = new Camera.CameraInfo(); for(int i = 0; i< Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, inf); if(inf.facing==Camera.CameraInfo.CAMERA_FACING_FRONT) { return Camera.open(i); } } return null; }
Upd2 - yes, explicit format and encoder settings solved the problem -
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
Perhaps because of the pre-build formats for the rear camera ... But it's weird.
source share