Mediarecorder无法录制来自前置摄像头的视频仅景观模式android

时间:2015-06-23 13:21:19

标签: android android-mediarecorder

我正在开发应用程序,它使用媒体记录器从后置摄像头和前置摄像头调制视频。我面临的问题是,每当我尝试以横向模式从前置摄像头录制视频时,视频根本没有被录制,肖像模式记录得很好而没有任何问题。

我在许多设备上测试了此代码,运行软件的设备成功运行代码并录制视频,但运行kitkat(三星注2)及以上的设备在横向模式下无法记录前置摄像头的视频。

Camera.Parameters parameters = mCamera.getParameters();
            List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
            Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes,
                    mPreview.getWidth(), mPreview.getHeight());

            // Use the same size for recording profile.
            CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
            profile.videoFrameWidth = optimalSize.width;
            profile.videoFrameHeight = optimalSize.height;
    enter code here
            // likewise for the camera object itself.
            parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mCamera.setParameters(parameters);
            if (isCamera) {
                try {
                    // Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
                    // with {@link SurfaceView}
                    mCamera.setPreviewTexture(mPreview.getSurfaceTexture());
                } catch (IOException e) {
                    Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
                    return false;
                }
            }
            // END_INCLUDE (configure_preview)


            // BEGIN_INCLUDE (configure_media_recorder)
            mMediaRecorder = new MediaRecorder();

            // Step 1: Unlock and set camera to MediaRecorder
            mCamera.unlock();

            mMediaRecorder.setCamera(mCamera);
            int orianton = getScreenOrientation();
            String str = getRotation(Capture_video.this);
            if (orianton == 1) {
                if (cameraFront) {
                    mMediaRecorder.setOrientationHint(270);
                } else {
                    mMediaRecorder.setOrientationHint(90);
                }

            } else if (orianton == 2) {


                if (str.equals("landscape")) {
                    mMediaRecorder.setOrientationHint(0);

                } else {
                    mMediaRecorder.setOrientationHint(180);
                }

            } else {
                mMediaRecorder.setOrientationHint(0);
            }

            // Step 2: Set sources
            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            //mMediaRecorder.setOrientationHint(rotation);
            // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
            mMediaRecorder.setProfile(profile);
            // mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
            mMediaRecorder.setVideoEncodingBitRate(690000);
            mMediaRecorder.setVideoFrameRate(20);
            // Step 4: Set output file
            mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
                    CameraHelper.MEDIA_TYPE_VIDEO).toString());
            // END_INCLUDE (configure_media_recorder)

            // Step 5: 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;


try {

                    mMediaRecorder.start();

                }catch (Exception e){
                    e.printStackTrace();
                }


  // dimensions of our preview surface.




And below is my logcat during error..please give me response as soon as possible..






 java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.os.AsyncTask$3.done(AsyncTask.java:300)
            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
            at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
     Caused by: java.lang.RuntimeException: start failed.
            at android.media.MediaRecorder.start(Native Method)
            at com.mansainfotech.Camera.Capture_video$MediaPrepareTask.doInBackground(Capture_video.java:656)
            at com.mansainfotech.Camera.Capture_video$MediaPrepareTask.doInBackground(Capture_video.java:648)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
06-23 18:31:59.731  28697-28697/com.mansainfotech.sportseed E/ActivityThread﹕ Activity com.mansainfotech.Camera.Capture_video has leaked IntentReceiver com.mansainfotech.Camera.UpdateService@42ce0dd8 that was originally registered here. Are you missing a call to unregisterReceiver()?
    android.app.IntentReceiverLeaked: Activity com.mansainfotech.Camera.Capture_video has leaked IntentReceiver com.mansainfotech.Camera.UpdateService@42ce0dd8 that was originally registered here. Are you missing a call to unregisterReceiver()?
            at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:809)
            at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:610)
            at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1816)
            at android.app.ContextImpl.registerReceiver(ContextImpl.java:1796)
            at android.app.ContextImpl.registerReceiver(ContextImpl.java:1790)
            at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:479)
            at com.mansainfotech.Camera.Capture_video.onCreate(Capture_video.java:146)
            at android.app.Activity.performCreate(Activity.java:5451)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
            at android.app.ActivityThread.access$900(ActivityThread.java:175)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5602)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案