回答

6

您可以使用MediaRecorder不調用setAudio *就可以了。這是使用MediaRecorder我的第一次,但這個例子似乎工作:

public class CamcorderView extends SurfaceView implements 
     SurfaceHolder.Callback { 

    private SurfaceHolder mHolder; 

    private Camera mCamera; 
    private MediaRecorder mRecorder; 

    public CamcorderView(Context context, AttributeSet attrs) { 
     super(context, attrs); 

     mHolder = getHolder(); 
     mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
     mHolder.addCallback(this); 

     mCamera = Camera.open(); 
     mRecorder = new MediaRecorder(); 

    } 

    public void stop() { 
     mRecorder.stop(); 
    } 

    @Override 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, 
      int height) { 
    } 

    @Override 
    public void surfaceDestroyed(SurfaceHolder holder) { 
    } 

    @Override 
    public void surfaceCreated(SurfaceHolder holder) { 
     mCamera.unlock(); 
     mRecorder.setCamera(mCamera); 

     mRecorder.setPreviewDisplay(mHolder.getSurface()); 

     // You may want to change these 
     mRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
     mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); 
     mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); 

     // You'll definitely want to change this 
     mRecorder.setOutputFile("/mnt/sdcard/out"); 

     try { 
      mRecorder.prepare(); 
     } catch (IllegalStateException e) { 
      Log.e("IllegalStateException", e.toString()); 
     } catch (IOException e) { 
      Log.e("IOException", e.toString()); 
     } 
     mRecorder.start(); 

    } 
} 

你也可以撥打:

  • setVideoSize(int, int);
  • setVideoFrameRate(int);
+1

謝謝!真的行!也許你知道如何將這些設置應用於CamcorderProfile?因爲我使用自動生成的PARAMS如'camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);',那麼所有的設置都爲'mediaRecorder.setProfile(camcorderProfile)施加; ' – Sergii 2012-08-12 16:09:34

+0

你能否提供更多的信息,因爲它不適合工作。 – 2015-09-10 08:39:12

9

你可以準備MediaRecorder通過從內置配置文件(CamcorderProfile)複製必需的字段。只是忽略音頻設置,你應該很好去。編輯下面的代碼以滿足您的需求,第3步是此處的重要部分。

private boolean prepareVideoRecorder() { 

    mCamera = getCameraInstance(); 
    mMediaRecorder = new MediaRecorder(); 

    // store the quality profile required 
    CamcorderProfile profile = CamcorderProfile.get(cameraid, CamcorderProfile.QUALITY_HIGH); 

    // Step 1: Unlock and set camera to MediaRecorder 
    mCamera.unlock(); 
    mMediaRecorder.setCamera(mCamera); 

    // Step 2: Set sources 
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 

    // Step 3: Set all values contained in profile except audio settings 
    mMediaRecorder.setOutputFormat(profile.fileFormat); 
    mMediaRecorder.setVideoEncoder(profile.videoCodec); 
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate); 
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate); 
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); 

    // Step 4: Set output file 
    mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString()); 

    // Step 5: Set the preview output 
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 

    // Step 6: Prepare configured MediaRecorder 
    try { 
     mMediaRecorder.prepare(); 
    } catch (IllegalStateException e) { 
     releaseMediaRecorder(); 
     return false; 
    } catch (IOException e) { 
     releaseMediaRecorder(); 
     return false; 
    } 
    return true; 
} 
+0

效果不錯..謝謝 – 2016-02-19 01:40:21

+0

不錯的解決方案......它對我非常有用..... – jack 2016-07-01 19:37:32