2012-06-21 72 views
1

我想在android(2.3.3)上刪除一個相機應用程序。使用eclipse和android模擬器(所以沒有設備)。我的應用程序有兩個功能:拍照和拍攝視頻。只需一個開關按鈕即可改變模式。第一個工作正常,但視頻有問題。模擬器上的Android視頻捕獲

第一個錯誤是:「在無效狀態下調用的setOutputFormat:4」。嘗試設置MediaRecorder的輸出格式。如果我忽略這個(使其成爲一個註釋行)然後我得到的「媒體服務器死了,攝像機服務器死亡」的錯誤(錯誤100)

我是一個新的Android開發人員,所以我只是用這個教程:http://developer.android.com/guide/topics/media/camera.html

這些錯誤的原因可能是,我試圖用沒有設備測試?

這裏是清單permissinos:

<uses-sdk android:minSdkVersion="10" /> 

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" /> 
<uses-feature android:name="android.hardware.camera" android:required="false" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 
<uses-permission android:name="android.permission.RECORD_VIDEO"/> 

這裏是發生這些錯誤代碼:

private boolean prepareVideoRecorder() { 


    mMediaRecorder = new MediaRecorder(); 
    mMediaRecorder.reset(); 

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

    // Set sources 
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 


    // Set output format and encoding 
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); 

    // Set a CamcorderProfile (requires API Level 8 or higher) 
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); 


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

    // Set the preview output 
    mMediaRecorder.setPreviewDisplay(mPreview.getmHolder().getSurface()); 

    // Prepare configured MediaRecorder 
    try { 
     mMediaRecorder.prepare(); 
    } catch (IllegalStateException e) { 
     Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage()); 
     releaseMediaRecorder(); 
     return false; 
    } catch (IOException e) { 
     Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage()); 
     releaseMediaRecorder(); 
     return false; 
    } 
    return true; 
} 

private void videoRecording() { 
    if (isRecording) { 
     // stop recording and release camera 
     mMediaRecorder.stop(); // stop the recording 
     releaseMediaRecorder(); // release the MediaRecorder object 
     mCamera.lock();   // take camera access back from MediaRecorder 

     // inform the user that recording has stopped 
     captureButton.setText(R.string.capture); 
     isRecording = false; 
    } else { 
     // initialize video camera 
     if (prepareVideoRecorder()) { 
      // Camera is available and unlocked, MediaRecorder is prepared, 
      // now you can start recording 
      mMediaRecorder.start(); 

      captureButton.setText(R.string.stop); 
      isRecording = true; 
     } else { 
      // prepare didn't work, release the camera 
      releaseMediaRecorder(); 
     } 
    } 
} 

這裏是logcat的輸出:

06-21 16:27:24.034: E/MediaRecorder(329): setOutputFormat called in an invalid state: 4 
06-21 16:27:24.034: D/AndroidRuntime(329): Shutting down VM 
06-21 16:27:24.054: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception  (group=0x40015560) 
06-21 16:27:24.054: E/AndroidRuntime(329): FATAL EXCEPTION: main 
06-21 16:27:24.054: E/AndroidRuntime(329): java.lang.IllegalStateException 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.media.MediaRecorder.setOutputFormat(Native Method) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.media.MediaRecorder.setProfile(MediaRecorder.java:286) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.bor.Fotograf.AndroidFotoActivity.prepareVideoRecorder(AndroidFotoActivity.java:221) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.bor.Fotograf.AndroidFotoActivity.videoRecording(AndroidFotoActivity.java:257) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.bor.Fotograf.AndroidFotoActivity.access$9(AndroidFotoActivity.java:245) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.bor.Fotograf.AndroidFotoActivity$6.onClick(AndroidFotoActivity.java:107) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.view.View.performClick(View.java:2485) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.view.View$PerformClick.run(View.java:9080) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.os.Handler.handleCallback(Handler.java:587) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:92) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123) 
06-21 16:27:24.054: E/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:3683) 
06-21 16:27:24.054: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method) 
06-21 16:27:24.054: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:507) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
06-21 16:27:24.054: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
06-21 16:27:24.054: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method) 

回答

0

至於你說的,您需要有一個設備來測試視頻和麥克風功能,srry!

也許你可以嘗試使用虛擬機,你可以嘗試安裝它。

在這裏你可以找到如何安裝虛擬機;)

http://osxdaily.com/2012/02/23/android-4-ics-virtualbox/

+1

我認爲你是正確的,但我想,我不能測試,但仍然我沒有得到這個錯誤。我會嘗試你的建議謝謝你。 – buttib

+1

這不是問題的答案。我在Samsung Ace todey上測試過它。錯誤仍然存​​在。我同意你的意見,我需要一個設備來測試,但錯誤還有另一個原因, – buttib