0

タブレットの前面カメラとその実行中の 2.2 Android Froyo からビデオをキャプチャしようとしています。このエラーの背後にある理由を実際に理解することはできません。タブレットは Tegra 2 Nvigia チップセットであるため、問題が発生する可能性があります。タブレットにはフロント カメラがあります。誰でも私が理解する方向を教えてください。

これは私が使用しているコードです、

                    Camera cam = openFrontFacingCamera();
                    m_recorder = new MediaRecorder();
                    cam.unlock();
                    m_recorder.setCamera(cam);
                    m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    m_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                    m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                    m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
                    m_recorder.setMaxDuration((int) 1000); 
                    m_recorder.setVideoSize(320, 240); 
                    m_recorder.setVideoFrameRate(15); 
                    m_recorder.setOutputFile("/sdcard/myvideo");

                    try {
                        m_recorder.prepare();
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                  // CRASHING HERE:
                    m_recorder.start();

これは、このメソッドの前に使用するカメラの初期化関数です

              private Camera openFrontFacingCamera() {
                    Camera camera = null;

                    // Look for front-facing camera, using the Gingerbread API.
                    // Java reflection is used for backwards compatibility with pre-Gingerbread APIs.
                    try {
                        Class<?> cameraClass = Class.forName("android.hardware.Camera");
                        Object cameraInfo = null;
                        Field field = null;
                        int cameraCount = 0;
                        Method getNumberOfCamerasMethod = cameraClass.getMethod( "getNumberOfCameras" );
                        if ( getNumberOfCamerasMethod != null ) {
                            cameraCount = (Integer) getNumberOfCamerasMethod.invoke( null, (Object[]) null );
                        }
                        Class<?> cameraInfoClass = Class.forName("android.hardware.Camera$CameraInfo");
                        if ( cameraInfoClass != null ) {
                            cameraInfo = cameraInfoClass.newInstance();
                        }
                        if ( cameraInfo != null ) {
                            field = cameraInfo.getClass().getField( "facing" );
                        }
                        Method getCameraInfoMethod = cameraClass.getMethod( "getCameraInfo", Integer.TYPE, cameraInfoClass );
                        if ( getCameraInfoMethod != null && cameraInfoClass != null && field != null ) {
                            for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) {
                                getCameraInfoMethod.invoke( null, camIdx, cameraInfo );
                                int facing = field.getInt( cameraInfo );
                                if ( facing == 1 ) { // Camera.CameraInfo.CAMERA_FACING_FRONT
                                    try {
                                        Method cameraOpenMethod = cameraClass.getMethod( "open", Integer.TYPE );
                                        if ( cameraOpenMethod != null ) {
                                            camera = (Camera) cameraOpenMethod.invoke( null, camIdx );
                                        }
                                    } catch (RuntimeException e) {
                                        Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
                                    }
                                }
                            }
                        }
                    }
                    // Ignore the bevy of checked exceptions the Java Reflection API throws - if it fails, who cares.
                    catch ( ClassNotFoundException e        ) {Log.e(TAG, "ClassNotFoundException" + e.getLocalizedMessage());}
                    catch ( NoSuchMethodException e         ) {Log.e(TAG, "NoSuchMethodException" + e.getLocalizedMessage());}
                    catch ( NoSuchFieldException e          ) {Log.e(TAG, "NoSuchFieldException " + e.getLocalizedMessage());}
                    catch ( IllegalAccessException e        ) {Log.e(TAG, "IllegalAccessException" + e.getLocalizedMessage());}
                    catch ( InvocationTargetException e     ) {Log.e(TAG, "InvocationTargetException" + e.getLocalizedMessage());}
                    catch ( InstantiationException e        ) {Log.e(TAG, "InstantiationException" + e.getLocalizedMessage());}
                    catch ( SecurityException e             ) {Log.e(TAG, "SecurityException" + e.getLocalizedMessage());}

                    if ( camera == null ) {
                        // Try using the pre-Gingerbread APIs to open the camera.
                        try {
                            camera = Camera.open();
                        } catch (RuntimeException e) {
                            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
                        }
                    }

                    return camera;
                }

これはエラーです:

            07-03 08:01:09.220: A/dalvikvm(32523): Exception!!! threadid=1: thread exiting with uncaught exception (group=0x4001d860)
            07-03 08:01:09.230: E/AndroidRuntime(32523): FATAL EXCEPTION: main
            07-03 08:01:09.230: E/AndroidRuntime(32523): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.webvideo.com/com.webvideo.com.MainActivity}: java.lang.IllegalStateException
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.os.Handler.dispatchMessage(Handler.java:99)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.os.Looper.loop(Looper.java:123)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread.main(ActivityThread.java:4627)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at java.lang.reflect.Method.invokeNative(Native Method)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at java.lang.reflect.Method.invoke(Method.java:521)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at dalvik.system.NativeStart.main(Native Method)
            07-03 08:01:09.230: E/AndroidRuntime(32523): Caused by: java.lang.IllegalStateException
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.media.MediaRecorder.start(Native Method)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at com.webvideo.com.MainActivity.onCreate(MainActivity.java:71)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
            07-03 08:01:09.230: E/AndroidRuntime(32523):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
4

1 に答える 1

0

コードが示すように、フロント カメラの API は Android 2.3 (gingerbread) で導入されました。

Froyoでは動作しません。

于 2012-07-03T08:49:54.993 に答える