0

ビデオを録画して再生しようとしています

ビデオの録画を開始すると、多くのデバイスがクラッシュすることに気付きました。

logcat から、問題はビデオのサイズにあることに気付きました。

カメラ ビューが小さく、数ピクセルです。これが問題ですか?

何を修正する必要がありますか? どのように?

private boolean prepareVideoRecorder() {

        mMediaRecorder = new MediaRecorder();

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

        // Step 2: Set sources
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
        mMediaRecorder.setProfile(CamcorderProfile
                .get(CamcorderProfile.QUALITY_HIGH));

        // Step 4: Set output file
        mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
                .toString());
        outputFileName = getOutputMediaFile(MEDIA_TYPE_VIDEO).toString();
        Log.d(TAG,"idan outputFileName" + outputFileName);


        // Step 5: Set the preview output
        // mMediaRecorder.setVideoSize(640, 480); //try
        mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

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




 public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview.





     Log.d(TAG,"surfaceCreated camera id" + mCamera );

     try {
            CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
            Camera.Parameters parameters = mCamera.getParameters();
            parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mCamera.setParameters(parameters);
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        }
        catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        }
}

logcat エラー:

06-02 19:29:14.177: D/CameraSource(115): Camera does not support setVideoSize()
06-02 19:29:14.177: D/CameraSource(115): Requested video size (1920x1088) isSetVideoSizeSupportedByCamera 0
06-02 19:29:14.177: E/CameraSource(115): Video dimension (1920x1088) is unsupported
06-02 19:29:14.177: D/CameraService(115): unlock (pid 115)
06-02 19:29:14.177: D/QualcommCameraHardwareZSL(115): virtual bool android::QualcommCameraHardware::recordingEnabled() recordingState=0
06-02 19:29:14.177: D/CameraService(115): clear mCameraClient (pid 115)
06-02 19:29:14.177: E/MediaRecorder(30873): start failed: -19
06-02 19:29:14.177: V/MediaRecorderJNI(30873): process_media_recorder_call
06-02 19:29:14.177: E/MediaRecorder(30873): start failed.
06-02 19:29:14.177: E/MediaRecorder(30873): try to delete broken file: /mnt/sdcard/Movies/Your_voice/Your_voice020613_192914.mp4
06-02 19:29:14.187: D/AndroidRuntime(30873): Shutting down VM
06-02 19:29:14.187: W/dalvikvm(30873): threadid=1: thread exiting with uncaught exception (group=0x40ac3228)
06-02 19:29:14.187: E/AndroidRuntime(30873): FATAL EXCEPTION: main
06-02 19:29:14.187: E/AndroidRuntime(30873): java.lang.RuntimeException: start failed.
06-02 19:29:14.187: E/AndroidRuntime(30873):    at android.media.MediaRecorder._start(Native Method)
06-02 19:29:14.187: E/AndroidRuntime(30873):    at android.media.MediaRecorder.start(MediaRecorder.java:712)
06-02 19:29:14.187: E/AndroidRuntime(30873):    at com.example.uploadvideo.MainActivity.onPlaying(MainActivity.java:165)
4

2 に答える 2

2

CamcorderProfile.get(int)デフォルト (リア) カメラのプロファイルを返します。mCamera がフロント カメラの場合、適切な cameraId でCamcorderProfile.get(int, int)を使用する必要があります。

于 2013-06-02T19:21:25.897 に答える
0

/** Camera オブジェクトのインスタンスを安全に取得する方法。*/

public Camera getCameraInstance () {
    Camera c = null;
    try {
        c = Camera.open(Camera.getNumberOfCameras() - 1);
    } catch (Exception e) {
        e.printStackTrace();
        onError();
    }
    return c;
}
于 2013-07-11T11:18:20.157 に答える