【问题标题】:Mediarecorder start failed -19Mediarecorder 启动失败 -19
【发布时间】:2012-06-30 06:26:22
【问题描述】:

为 mediarecorder 运行 start() 时出现此错误。

06-28 18:46:22.570: E/MediaRecorder(9540): start failed: -19
06-28 18:46:22.570: W/System.err(9540): java.lang.RuntimeException: start failed.

我正在扩展 mediarecorder 类
我的代码:

camera = Camera.open(cameraId);
super.setCamera(camera);
        super.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        super.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        if (mode==MODE_DEFAULT) {
            super.setMaxDuration(1000);
            super.setMaxFileSize(Integer.MAX_VALUE);
        } else {
            // On some phones a RuntimeException might be thrown :/
            try {
                super.setMaxDuration(0);
                super.setMaxFileSize(Integer.MAX_VALUE); 
            } catch (RuntimeException e) {
                Log.e(TAG,"setMaxDuration or setMaxFileSize failed !");
            }
        }
        super.setVideoEncoder(videoEncoder);
        if(surfaceHolder!=null)
        super.setPreviewDisplay(surfaceHolder.getSurface());
        //super.setVideoSize(quality.resX,quality.resY);
        super.setVideoFrameRate(quality.frameRate);
        super.setVideoEncodingBitRate(quality.bitRate);

我看到了这些页面
Error opening android camera for streaming video
Android MediaRecorder - "start failed: -19"
但没有一个对我有用...
在archos 80 g9,android 3.2上运行 有人有什么想法吗?

【问题讨论】:

  • 您可能应该发布用于准备 MediaRecorder 和设置相机的代码,这就是导致问题的原因。您还应该在日志中包含更多内容。

标签: android mediarecorder


【解决方案1】:

这里的问题是关于camera。只需使用camera.unlock() 允许媒体进程访问相机。

这必须在调用 MediaRecorder.setCamera(Camera) 之前完成。录制开始后无法调用。

阅读更多here。

【讨论】:

    【解决方案2】:

    这段代码对我有用(找到here)

    mCamera.unlock(); // maybe not for your activity flow
    
    //1st. Initial state
    mProfile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setCamera( mCamera );
    
    //2nd. Initialized state
    mMediaRecorder.setAudioSource( MediaRecorder.AudioSource.CAMCORDER );
    mMediaRecorder.setVideoSource( MediaRecorder.VideoSource.CAMERA );
    
    //3rd. config
    mMediaRecorder.setOutputFormat( mProfile.fileFormat );
    mMediaRecorder.setAudioEncoder( mProfile.audioCodec );
    mMediaRecorder.setVideoEncoder( mProfile.videoCodec );
    mMediaRecorder.setOutputFile( "/sdcard/FBVideo.3gp" );
    mMediaRecorder.setVideoSize( mProfile.videoFrameWidth, mProfile.videoFrameHeight );
    mMediaRecorder.setVideoFrameRate( mProfile.videoFrameRate );
    mMediaRecorder.setVideoEncodingBitRate( mProfile.videoBitRate );
    mMediaRecorder.setAudioEncodingBitRate( mProfile.audioBitRate );
    mMediaRecorder.setAudioChannels( mProfile.audioChannels );
    mMediaRecorder.setAudioSamplingRate( mProfile.audioSampleRate );
    mMediaRecorder.setPreviewDisplay( mHolder.getSurface() );
    
    try {
        mMediaRecorder.prepare();
        mMediaRecorder.start();
    } catch ( IllegalStateException e ) {
        e.printStackTrace();
    } catch ( IOException e ) {
        e.printStackTrace();
    }
    

    【讨论】:

      【解决方案3】:

      我在视频录制过程中遇到了同样的问题,我通过添加此视频录制解决了这个问题

      /**
       * Start video recording by cleaning the old camera preview
       */
      private void startVideoRecorder() {
          // THIS IS NEEDED BECAUSE THE GLASS CURRENTLY THROWS AN ERROR OF
          // "MediaRecorder start failed: -19"
          // THIS WONT BE NEEDED INCASE OF PHONE AND TABLET
          // This causes crash in glass kitkat version so remove it
          // try {
          // mCamera.setPreviewDisplay(null);
          // } catch (java.io.IOException ioe) {
          // Log.d(TAG,
          // "IOException nullifying preview display: "
          // + ioe.getMessage());
          // }
          // mCamera.stopPreview();
          // mCamera.unlock();
          recorder = new MediaRecorder();
          // Let's initRecorder so we can record again
          initRecorder();
      }
      
      /**
       * Initialize video recorder to record video
       */
      private void initRecorder() {
          try {
              File dir = new File(folderPath);
              if (!dir.exists()) {
                  dir.mkdirs();
              }
              mCamera.stopPreview();
              mCamera.unlock();
              videofile = new File(dir, fileName + ".mp4");
              recorder.setCamera(mCamera);
      
              // Step 2: Set sources
              recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
              recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      
              // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
              recorder.setProfile(CamcorderProfile
                      .get(CamcorderProfile.QUALITY_HIGH));
      
              // Step 4: Set output file
              recorder.setOutputFile(videofile.getAbsolutePath());
              // Step 5: Set the preview output
              recorder.setPreviewDisplay(mPreview.getHolder().getSurface());
              // Step 6: Prepare configured MediaRecorder
              recorder.setMaxDuration(video_duration * 1000);
              recorder.setOnInfoListener(new OnInfoListener() {
      
                  @Override
                  public void onInfo(MediaRecorder mr, int what, int extra) {
                      if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
      
                          mCamera.stopPreview();
                          releaseMediaRecorder();
      
                          /*
                           * initiate media scan and put the new things into the
                           * path array to make the scanner aware of the location
                           * and the files you want to see
                           */MediaScannerConnection.scanFile(
                                  CuxtomCamActivity.this,
                                  new String[] { videofile.getPath() }, null,
                                  null);
      
                          Intent intent = new Intent();
                          intent.putExtra(CuxtomIntent.FILE_PATH,
                                  videofile.getPath());
                          intent.putExtra(CuxtomIntent.FILE_TYPE, FILE_TYPE.VIDEO);
                          setResult(RESULT_OK, intent);
                          finish();
                      }
      
                  }
              });
              recorder.prepare();
              recorder.start();
          } catch (Exception e) {
              Log.e("Error Stating CuXtom Camera", e.getMessage());
          }
      }
      private void releaseMediaRecorder() {
          if (recorder != null) {
              recorder.reset(); // clear recorder configuration
              recorder.release(); // release the recorder object
              recorder = null;
          }
      }
      

      要查看相机实际实现的详细信息,请参阅Open Source Cuxtom Cam

      【讨论】:

        【解决方案4】:

        我在MediaRecorder.start() 方法的文档中发现了一个微妙的提示,提示它在尝试重新录制之前是否未能锁定()Camera。这对我有用。暗示 Camera 状态错误已在 API 级别 13 后修复 - 调用 Camera.lock() 是已知的解决方法。

        【讨论】:

          【解决方案5】:

          通过删除修复

          super.setVideoFrameRate(quality.frameRate);
          

          【讨论】:

            猜你喜欢
            • 2016-12-30
            • 1970-01-01
            • 1970-01-01
            • 2015-07-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多