0

我已經集成了攝像頭,允許用戶錄製時間流逝的視頻。當用戶錄製視頻時,取消按鈕在那裏允許用戶取消當前的錄製。我的問題是如果取消後,我試圖記錄我再次碰到下面的exception-Nullpointerexception如果嘗試取消後再次錄製視頻

java.lang.NullPointerException: Attempt to read from field 'int android.media.CamcorderProfile.fileFormat' on a null object reference 
     at android.media.MediaRecorder.setProfile(MediaRecorder.java:423) 
     at xyz.fragments.CameraFragment.prepareFastVideoRecorder(CameraFragment.java:448) 
     at xyz.fragments.CameraFragment.access$2300(CameraFragment.java:64) 
     at xyz.fragments.CameraFragment$6.onClick(CameraFragment.java:329) 
     at android.view.View.performClick(View.java:4756) 
     at android.view.View$PerformClick.run(View.java:19761) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5253) 
     at java.lang.reflect.Method.invoke(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

上線

mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P)); 

下面是我的代碼 -

start.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 



         if (prepareFastVideoRecorder()) { 

          mMediaRecorder.start(); 

         } else { 

          releaseMediaRecorder(); 
         } 
        } 
       } 
      } 
     }); 

stop.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 


        mMediaRecorder.stop(); // stop the recording 
        releaseMediaRecorder(); // release the MediaRecorder object 
        mCamera.lock();   // take camera access back from 
} 
}): 


private boolean prepareFastVideoRecorder() { 
    mMediaRecorder = new MediaRecorder(); 
    try { 
     mCamera.setPreviewDisplay(null); 
    } catch (java.io.IOException ioe) { 
     Log.e("Bhuvnesh", "IOException nullifying preview display: " + ioe.getMessage()); 
    } 
    mCamera.stopPreview(); 
    // Step 1: Unlock and set camera to MediaRecorder 
    mCamera.unlock(); 
    mMediaRecorder.setCamera(mCamera); 
    // Step 2: Set sources 
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P)); 
    //mMediaRecorder.setCaptureRate(0.1); // capture a frame every 10 seconds 
    mMediaRecorder.setCaptureRate(5); // capture a frame every 1 seconds 
    // Step 4: Set output file to the socket 
    mVideoFile = new File(getOutputMediaFile().toString()); 
    mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath()); 
    if (cameratype == 1) 
     mMediaRecorder.setOrientationHint(90); 
    else if (cameratype == 2) 
     mMediaRecorder.setOrientationHint(270); 
    mMediaRecorder.setMaxDuration(60000); 
    mMediaRecorder.setOnInfoListener(this); 
    // Step 5: Set the preview output 
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 
    try { 
     mMediaRecorder.prepare(); 
    } catch (IllegalStateException e) { 
     releaseMediaRecorder(); 
     return false; 
    } catch (IOException e) { 
     releaseMediaRecorder(); 
     return false; 
    } 
    return true; 
} 
+0

嘗試'mMediaRecorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_TIME_LAPSE_480P));' – JiTHiN

+1

感謝洛特!ü可以寫爲答案給予解釋,這樣我可以選擇它作爲最佳答案.. – Programmer

回答

2

您需要傳遞當前相機ID,同時使用get()CamcoderProfile。如果此參數未通過,它將返回默認相機的配置文件。

嘗試,

mMediaRecorder.setProfile(CamcorderProfile.get(camId,CamcorderProfile.QUALITY_TIME_LAPSE_480P)); 
+0

我試圖追加視頻這個庫-http://github.com/sannies/mp4parser ..它適用於追加相同的模式videos..but但我想附加不同的模式視頻 - 時間間隔和正常模式的視頻.. u有任何想法,我應該如何進行? – Programmer

+0

這是一個不同的話題。在聊天中繼續討論:http://chat.stackexchange.com/rooms/30426/video-concatenation – JiTHiN

+0

我必須有20個聲望在那裏談話..我想我會發表有關該問題的另一個問題.. – Programmer

相關問題