8

我的媒体录制出现问题。我正在尝试使用前置摄像头进行录制。这给了我一个错误(但预览正在运行)。每当我使用后置摄像头时,一切都很好,我觉得这很奇怪。可能是什么问题,解决方案是什么?我的代码和错误如下所示。

编辑。用VGA前置摄像头录制似乎不起作用。这怎么可能?虽然可以使用 HTC 相机应用程序进行录制。

提前谢谢你。

protected void startRecording() throws Exception 
{
    mrec = new MediaRecorder();
    mCamera.unlock();

    mrec.setCamera(mCamera);


    mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 

    mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    //mrec.setPreviewDisplay(surfaceHolder.getSurface());

    File picDirectory = new File(Environment.getExternalStorageDirectory() +"/TrouwApp");
    picDirectory.mkdirs();

    File mediaStorageDir = new File(Environment.getExternalStorageDirectory() +"/TrouwApp", "Videos");

    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
        }
    }

    mrec.setOutputFile( mediaStorageDir.getPath() + File.separator  + date + "_" + videonr+ ".3gp"); 

    mrec.prepare();
    mrec.start();//line 136

    Log.d(TAG, "Recording started!!");
}

添加到清单中的行:

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

错误日志:

08-25 23:25:25.332: V/MediaRecorderJNI(4989): 设置
08-25 23:25:25.362: V/MediaRecorder(4989): 构造函数
08-25 23:25:25.402:V/MediaRecorder(4989):doCleanUp
08-25 23:25:25.402:V/MediaRecorder(4989):setListener
08-25 23:25:25.402: V/MediaRecorderJNI(4989): setMediaRecorder E: mr = mr
08-25 23:25:25.402:V/MediaRecorderJNI(4989):setMediaRecorder X
08-25 23:25:25.402:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.402: V/MediaRecorderJNI(4989): JNIMediaRecorderListener::setCamera
08-25 23:25:25.402: V/MediaRecorder(4989): setCamera(0x16c2290,0x1c08dc8)
08-25 23:25:25.402: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.402: V/MediaRecorderJNI(4989): setVideoSource(1)
08-25 23:25:25.402:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.402: V/MediaRecorder(4989): setVideoSource(1)
08-25 23:25:25.402:V/MediaRecorder(4989):调用 init(),因为媒体记录器尚未初始化
08-25 23:25:25.402:V/MediaRecorder(4989):初始化
08-25 23:25:25.412: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.412: V/MediaRecorderJNI(4989): setAudioSource(1)
08-25 23:25:25.412:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.412: V/MediaRecorder(4989): setAudioSource(1)
08-25 23:25:25.412: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.502:V/MediaRecorderJNI(4989):setOutputFormat(2)
08-25 23:25:25.502:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.502:V/MediaRecorder(4989):setOutputFormat(2)
08-25 23:25:25.502: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.502: V/MediaRecorderJNI(4989): setVideoFrameRate(30)
08-25 23:25:25.502:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.502:V/MediaRecorder(4989):setVideoFrameRate(30)
08-25 23:25:25.502: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.502: V/MediaRecorderJNI(4989): setVideoSize(1920, 1088)
08-25 23:25:25.502:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.502: V/MediaRecorder(4989): setVideoSize(1920, 1088)
08-25 23:25:25.502: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.502: V/MediaRecorderJNI(4989): setParameter()
08-25 23:25:25.502:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.502: V/MediaRecorder(4989): setParameters(video-param-encoding-bitrate=12000000)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.512: V/MediaRecorderJNI(4989): setVideoEncoder(2)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:25.512: V/MediaRecorder(4989): setVideoEncoder(2)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.512: V/MediaRecorderJNI(4989): setParameter()
08-25 23:25:25.512: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:25.512: V/MediaRecorder(4989): setParameters(audio-param-encoding-bitrate=96000)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.512: V/MediaRecorderJNI(4989): setParameter()
08-25 23:25:25.512: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:25.512: V/MediaRecorder(4989): setParameters(audio-param-number-of-channels=1)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.512: V/MediaRecorderJNI(4989): setParameter()
08-25 23:25:25.512: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:25.512: V/MediaRecorder(4989): setParameters(audio-param-sampling-rate=48000)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.512: V/MediaRecorderJNI(4989): setAudioEncoder(3)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:25.512:V/MediaRecorder(4989):setAudioEncoder(3)
08-25 23:25:25.512: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.542:V/MediaRecorderJNI(4989):setOutputFile
08-25 23:25:25.542:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.542: V/MediaRecorder(4989): setOutputFile(60, 0, 0)
08-25 23:25:25.542: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.542: V/MediaRecorderJNI(4989): 准备
08-25 23:25:25.542:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.542: V/MediaRecorder(4989): 准备
08-25 23:25:25.542: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.542: V/MediaRecorderJNI(4989): 开始
08-25 23:25:25.552:V/MediaRecorderJNI(4989):getMediaRecorder E
08-25 23:25:25.552:V/MediaRecorder(4989):开始
08-25 23:25:25.562:E/MediaRecorder(4989):启动失败:-19
08-25 23:25:25.562: V/MediaRecorderJNI(4989): process_media_recorder_call
08-25 23:25:25.562: E/MediaRecorder(4989): 启动失败。
08-25 23:25:25.562:E/MediaRecorder(4989):尝试删除损坏的文件:/mnt/sdcard/TrouwApp/Videos/25-8-2013_0.3gp
08-25 23:25:25.562:D/videoActivity(4989):错误启动失败。
08-25 23:25:25.562: D/videoActivity(4989): 错误 java.lang.RuntimeException: 启动失败。
08-25 23:25:25.562: D/videoActivity(4989): 错误 java.lang.RuntimeException: 启动失败。
08-25 23:25:25.562: V/MediaRecorderJNI(4989): 发布
08-25 23:25:25.562: V/MediaRecorderJNI(4989): setMediaRecorder E: mr = null
08-25 23:25:25.562: V/MediaRecorderJNI(4989): setMediaRecorder X
08-25 23:25:25.562:V/MediaRecorder(4989):setListener
08-25 23:25:25.562:V/MediaRecorder(4989):发布
08-25 23:25:25.562: V/MediaRecorder(4989): 析构函数
08-25 23:25:25.562: D/videoActivity(4989): 开始录制错误
08-25 23:25:25.562: W/System.err(4989): java.lang.RuntimeException: 启动失败。
08-25 23:25:25.572:W/System.err(4989):在 android.media.MediaRecorder._start(本机方法)
08-25 23:25:25.572: W/System.err(4989): 在 android.media.MediaRecorder.start(MediaRecorder.java:712)
08-25 23:25:25.572: W/System.err(4989): 在 com.example.trouwapp.VideoActivity.startRecording(VideoActivity.java:136)
08-25 23:25:25.572: W/System.err(4989): 在 com.example.trouwapp.VideoActivity.onClick(VideoActivity.java:246)
08-25 23:25:25.572: W/System.err(4989): 在 android.view.View.performClick(View.java:3549)
08-25 23:25:25.572: W/System.err(4989): 在 android.view.View$PerformClick.run(View.java:14393)
08-25 23:25:25.582: W/System.err(4989): 在 android.os.Handler.handleCallback(Handler.java:605)
08-25 23:25:25.582: W/System.err(4989): 在 android.os.Handler.dispatchMessage(Handler.java:92)
08-25 23:25:25.582: W/System.err(4989): 在 android.os.Looper.loop(Looper.java:154)
08-25 23:25:25.582: W/System.err(4989): 在 android.app.ActivityThread.main(ActivityThread.java:4945)
08-25 23:25:25.582: W/System.err(4989): 在 java.lang.reflect.Method.invokeNative(Native Method)
08-25 23:25:25.582: W/System.err(4989): 在 java.lang.reflect.Method.invoke(Method.java:511)
08-25 23:25:25.582: W/System.err(4989): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-25 23:25:25.582: W/System.err(4989): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-25 23:25:25.592:W/System.err(4989):在 dalvik.system.NativeStart.main(本机方法)
08-25 23:25:55.582: V/MediaRecorderJNI(4989): native_reset
08-25 23:25:55.582: V/MediaRecorderJNI(4989): getMediaRecorder E
08-25 23:25:55.582: V/MediaRecorderJNI(4989): 发布
08-25 23:25:55.582: V/MediaRecorderJNI(4989): setMediaRecorder E: mr = null
08-25 23:25:55.582: V/MediaRecorderJNI(4989): setMediaRecorder X
08-25 23:25:56.002: D/AndroidRuntime(4989): 关闭虚拟机
08-25 23:25:56.002: W/dalvikvm(4989): threadid=1: 线程退出未捕获异常 (group=0x40ac8228)
4

2 回答 2

19

找到了解决方案。由于我使用的是前置摄像头,因此我需要从前置摄像头获取摄像机配置文件。我通过这样做实现了这一点:

mrec.setProfile(CamcorderProfile.get(1, CamcorderProfile.QUALITY_HIGH));

而不是这个:

mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
于 2013-08-27T23:21:49.150 回答
-2

试试这个:

StartRecording = false;

    if( mrec == null ) { 
        mrec = new MediaRecorder();
        mCamera.unlock();
        mrec.setCamera(mCamera);
        File picDirectory = new File(Environment.getExternalStorageDirectory() +"/TrouwApp");
        picDirectory.mkdirs();
        File mediaStorageDir = new File(Environment.getExternalStorageDirectory() +"/TrouwApp", "Videos");
        mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
        mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); //you forgot this
        mrec.setOutputFile( mediaStorageDir.getPath() + File.separator  + date + "_" + videonr+ ".3gp"); 
        mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //you forgot this also
        mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    }
    if(!StartRecording) {
    Log.d(TAG, "Recording stopped!!");
        try {
            mrec.prepare();
            mrec.start();
            StartRecording = true;
        }  catch (IOException e) {
            e.printStackTrace();
        }
    } else {
    Log.d(TAG, "Recording started!!");
        StartRecording = false;
        mrec.stop();
        mrec.reset();
        mrec.release();
        mrec = null;
    }//else
于 2013-08-27T22:46:53.370 回答