簡體   English   中英

在模擬器上捕獲 Android 視頻

[英]Android video capturing on emulator

我正在嘗試在 android(2.3.3) 上開發一個相機應用程序。 使用eclipse和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)

正如您所說,您需要有一個設備來測試視頻和麥克風功能,對不起!

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

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

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

沒有像 android.permission.RECORD_VIDEO 這樣的權限!!!

您可以在這里找到答案setOutputFormat called in an invalid state: 4 (where and why)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM