使用致命异常为相机崩溃添加缩放功能

时间:2012-01-12 11:02:15

标签: android android-camera

您好我正在尝试使用SurfaceView和Camera类制作相机。除了缩放功能外,一切正常。当我在开始使用MediaRecorder进行录制之前点击缩放时,它可以工作,但是如果我开始录制并点击缩放就会崩溃。这是我的代码。如何将缩放功能添加到相机中。任何帮助深表感谢。谢谢。

这是我对smoothZoom的代码,

 zoomControls.setOnZoomInClickListener(new OnClickListener() {

        public void onClick(View v) {

            try
            {
            currentZoomLevel++;
            myCamera.startSmoothZoom(currentZoomLevel);


            }catch(IllegalArgumentException e)
            {
                currentZoomLevel--;
                zoomControls.setIsZoomInEnabled(false);
            }
        }
    });


    Parameters parameters = myCamera.getParameters();
    parameters.setFlashMode(getFlashModeSetting());
    myCamera.setParameters(parameters);

    mediaRecorder = new MediaRecorder();
    myCamera.unlock();
    mediaRecorder.setCamera(myCamera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
    mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());

这是我的logact,

08-21 14:05:36.171: ERROR/AndroidRuntime(6426): FATAL EXCEPTION: main
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): java.lang.RuntimeException: start smooth zoom failed
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.hardware.Camera.startSmoothZoom(Native Method)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at com.camvideocorder.CamVideoCorderActivity$2.onClick(CamVideoCorderActivity.java:95)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.view.View.performClick(View.java:2485)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.view.View$PerformClick.run(View.java:9089)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.os.Handler.handleCallback(Handler.java:587)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.os.Looper.loop(Looper.java:123)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at android.app.ActivityThread.main(ActivityThread.java:3806)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at java.lang.reflect.Method.invoke(Method.java:507)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

您可以指定您使用的是哪个版本的Android吗?录制视频功能时只在android 4.0中添加。