2012-06-28 79 views
3

運行startrecorder()時出現此錯誤。Mediarecorder啓動失敗-19

06-28 18:46:22.570: E/MediaRecorder(9540): start failed: -19 
06-28 18:46:22.570: W/System.err(9540): java.lang.RuntimeException: start failed. 

我伸出mediarecorder類
我的代碼:

camera = Camera.open(cameraId); 
super.setCamera(camera); 
     super.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
     super.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); 
     if (mode==MODE_DEFAULT) { 
      super.setMaxDuration(1000); 
      super.setMaxFileSize(Integer.MAX_VALUE); 
     } else { 
      // On some phones a RuntimeException might be thrown :/ 
      try { 
       super.setMaxDuration(0); 
       super.setMaxFileSize(Integer.MAX_VALUE); 
      } catch (RuntimeException e) { 
       Log.e(TAG,"setMaxDuration or setMaxFileSize failed !"); 
      } 
     } 
     super.setVideoEncoder(videoEncoder); 
     if(surfaceHolder!=null) 
     super.setPreviewDisplay(surfaceHolder.getSurface()); 
     //super.setVideoSize(quality.resX,quality.resY); 
     super.setVideoFrameRate(quality.frameRate); 
     super.setVideoEncodingBitRate(quality.bitRate); 

我看到這些網頁
Error opening android camera for streaming video
Android MediaRecorder - "start failed: -19"
但他們不爲我工作...
上運行archos 80 g9,android 3.2 任何人有任何想法?

+0

發表了一些代碼。 –

+1

您應該發佈準備MediaRecorder的代碼並設置相機,這是造成問題的原因。你還應該在日誌中加入更多的方法。 – Guardanis

回答

4

修正去除

super.setVideoFrameRate(quality.frameRate); 
1

我發現了MediaRecorder.start()方法的文檔微妙的暗示,暗示如果它不能試圖重新錄製之前鎖定()的Camera。這對我有效。暗示Camera狀態錯誤在API級別13後被修復 - 調用Camera.lock()是已知的解決方法。

2

我面臨錄像在同一proble我加入此視頻錄製

/** 
* Start video recording by cleaning the old camera preview 
*/ 
private void startVideoRecorder() { 
    // THIS IS NEEDED BECAUSE THE GLASS CURRENTLY THROWS AN ERROR OF 
    // "MediaRecorder start failed: -19" 
    // THIS WONT BE NEEDED INCASE OF PHONE AND TABLET 
    // This causes crash in glass kitkat version so remove it 
    // try { 
    // mCamera.setPreviewDisplay(null); 
    // } catch (java.io.IOException ioe) { 
    // Log.d(TAG, 
    // "IOException nullifying preview display: " 
    // + ioe.getMessage()); 
    // } 
    // mCamera.stopPreview(); 
    // mCamera.unlock(); 
    recorder = new MediaRecorder(); 
    // Let's initRecorder so we can record again 
    initRecorder(); 
} 

/** 
* Initialize video recorder to record video 
*/ 
private void initRecorder() { 
    try { 
     File dir = new File(folderPath); 
     if (!dir.exists()) { 
      dir.mkdirs(); 
     } 
     mCamera.stopPreview(); 
     mCamera.unlock(); 
     videofile = new File(dir, fileName + ".mp4"); 
     recorder.setCamera(mCamera); 

     // Step 2: Set sources 
     recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); 
     recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 

     // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) 
     recorder.setProfile(CamcorderProfile 
       .get(CamcorderProfile.QUALITY_HIGH)); 

     // Step 4: Set output file 
     recorder.setOutputFile(videofile.getAbsolutePath()); 
     // Step 5: Set the preview output 
     recorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 
     // Step 6: Prepare configured MediaRecorder 
     recorder.setMaxDuration(video_duration * 1000); 
     recorder.setOnInfoListener(new OnInfoListener() { 

      @Override 
      public void onInfo(MediaRecorder mr, int what, int extra) { 
       if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { 

        mCamera.stopPreview(); 
        releaseMediaRecorder(); 

        /* 
        * initiate media scan and put the new things into the 
        * path array to make the scanner aware of the location 
        * and the files you want to see 
        */MediaScannerConnection.scanFile(
          CuxtomCamActivity.this, 
          new String[] { videofile.getPath() }, null, 
          null); 

        Intent intent = new Intent(); 
        intent.putExtra(CuxtomIntent.FILE_PATH, 
          videofile.getPath()); 
        intent.putExtra(CuxtomIntent.FILE_TYPE, FILE_TYPE.VIDEO); 
        setResult(RESULT_OK, intent); 
        finish(); 
       } 

      } 
     }); 
     recorder.prepare(); 
     recorder.start(); 
    } catch (Exception e) { 
     Log.e("Error Stating CuXtom Camera", e.getMessage()); 
    } 
} 
private void releaseMediaRecorder() { 
    if (recorder != null) { 
     recorder.reset(); // clear recorder configuration 
     recorder.release(); // release the recorder object 
     recorder = null; 
    } 
} 

若要查看如何將攝像機實際執行的細節解決它指Open Source Cuxtom Cam

+0

mCamera.unlock();爲我工作。謝謝 –

+0

mCamera.unlock();爲我工作。謝謝 –

0

此代碼工作(找到here

mCamera.unlock(); // maybe not for your activity flow 

//1st. Initial state 
mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); 
mMediaRecorder = new MediaRecorder(); 
mMediaRecorder.setCamera(mCamera); 

//2nd. Initialized state 
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); 
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 

//3rd. config 
mMediaRecorder.setOutputFormat(mProfile.fileFormat); 
mMediaRecorder.setAudioEncoder(mProfile.audioCodec); 
mMediaRecorder.setVideoEncoder(mProfile.videoCodec); 
mMediaRecorder.setOutputFile("/sdcard/FBVideo.3gp"); 
mMediaRecorder.setVideoSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight); 
mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate); 
mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate); 
mMediaRecorder.setAudioEncodingBitRate(mProfile.audioBitRate); 
mMediaRecorder.setAudioChannels(mProfile.audioChannels); 
mMediaRecorder.setAudioSamplingRate(mProfile.audioSampleRate); 
mMediaRecorder.setPreviewDisplay(mHolder.getSurface()); 

try { 
    mMediaRecorder.prepare(); 
    mMediaRecorder.start(); 
} catch (IllegalStateException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
}