视频在开始时显示黑屏

时间:2019-07-02 12:19:25

标签: android camera surfaceview

我在单击按钮时使用surfaceviwe录制视频,但开始时显示黑屏。我不知道我哪里错了。我累了很多东西,但是不工作。

       private void initRecorder(Surface surface) throws IOException
      if(mCamera == null) {
        mCamera = Camera.open();
        mCamera.setDisplayOrientation(90);
        mCamera.setPreviewDisplay(mHolder);
        mCamera.unlock();

    if(mMediaRecorder == null)
        mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setPreviewDisplay(surface);
        mMediaRecorder.setCamera(mCamera);
    String pathname=createDirectoryAndSaveFile();
    SharedPreferences sharedPreferences=getSharedPreferences("shared", 
     Context.MODE_PRIVATE);
    SharedPreferences.Editor editor=sharedPreferences.edit();
    editor.putString("videopath",pathname);
    editor.commit();
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setOutputFile(pathname);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoEncodingBitRate(3000000);
    //mMediaRecorder.setVideoSize(1920,1080);
    mMediaRecorder.setVideoSize(1280,720);
    mMediaRecorder.setOrientationHint(90);
    mMediaRecorder.prepare();
    mInitSuccesful = true;
}

我想在开始时摄像机显示预览

0 个答案:

没有答案