简体   繁体   中英

Android video capturing on emulator

I'm trying to delevop a camera application on android(2.3.3). Using eclipse and android emulator(so there is no device). My app has two features: taking picture and capturing video. With one switch button it can be changed the mode. The first one is working fine but the video one has problems.

The first error is: "setOutputFormat called in an invalid state: 4". While trying set output format of MediaRecorder. If i ignore this(make it a comment line) then i get "Media server died,camera server died" errors(Error 100)

I'm a new android developer so i'm just using this tutorial: http://developer.android.com/guide/topics/media/camera.html

Is these errors' reason can be that i'm trying to test with no device?

here is the manifest 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"/>

Here is the code which occurs these errors:

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();
        }
    }
}

And here is the logcat output:

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)

As you said, you need to have a device to test de video and mic functionalities, srry!

Maybe you can try to use a virtual machine and you can try to install it.

here you can find how to install the virtual machine;)

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

There is no permission as android.permission.RECORD_VIDEO!!!

You may be able to find the answer here setOutputFormat called in an invalid state: 4 (where and why)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM