E / CameraSource:无法开始录制,收到错误:功能未实现(-38)

时间:2016-10-03 15:56:21

标签: android mediarecorder video-recording

我在MediaRecorder上调用prepare方法从服务中的一个线程来录制视频。

 private Runnable mRunnable = new Runnable() {
    @Override
    public void run() {
        try {
            if (prepareMediaRecorder()) {
                mediaRecorder.start();
            } else {
                releaseMediaRecorder();
            }
        } catch (Exception e) {
            e.printStackTrace();
            SpyCameraUtility.showToast(SecretRecordingApplication.getAppState(), "Camera is used by other application , can't record.");
            FirebaseCrash.report(e);
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    finishService();
                }
            });
        }
    }
};
  

  private boolean prepareMediaRecorder() {
    mediaRecorder = new MediaRecorder();
    if (recordingType == Constants.MEDIA_TYPE_VIDEO || recordingType == Constants.MEDIA_TYPE_INSTANT) {
        if (chooseCamera() == null)
            return false;
        try {
            mCamera.setPreviewTexture(textureView.getSurfaceTexture());
        } catch (IOException e) {
            Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
            FirebaseCrash.report(e);
            return false;
        }
        mCamera.unlock();
        mediaRecorder.setCamera(mCamera);
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mediaRecorder.setOrientationHint(rotation);
        mediaRecorder.setProfile(getCamcorderProfile());
        recordingFilePath = SpyCameraUtility.openFileForStorage(this, 0, recordedFileInfo).getAbsolutePath();
        mediaRecorder
                .setOutputFile(recordingFilePath);// video


    } else if (recordingType == Constants.MEDIA_TYPE_AUDIO) {

        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recordingFilePath = SpyCameraUtility.openFileForStorage(this, 1, recordedFileInfo).getAbsolutePath();
        mediaRecorder
                .setOutputFile(recordingFilePath);// audio



    }
    Intent i = new Intent(Constants.ACTION_START_SERVICE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);

    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
        releaseMediaRecorder();
        showUnknownError(e);
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        releaseMediaRecorder();
        showUnknownError(e);
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        showUnknownError(e);
        return false;
    }
    return true;

}

有时它会给我以下错误

10-03 21:22:43.738 3099-12598/? E/CameraClient: mSurface or mPreviewWindow must be set before startRecordingMode.

10-03 21:22:43.738 3099-12598 /? E / CameraSource:无法开始录制,收到错误:功能未实现(-38) 10-03 21:22:43.738 3099-3780 /? D / MPEG4Writer:停止编写器线程 10-03 21:22:43.748 3099-12597 /? D / MPEG4Writer:在最后一批中写入0个块 10-03 21:22:43.748 3099-3780 /? D / MPEG4Writer:写入程序线程已停止 10-03 21:22:43.748 3099-3780 /? D / MPEG4Writer:视频轨道停止 10-03 21:22:43.748 3099-3780 /? E / MPEG4Writer:调用了Stop()但未启动track 10-03 21:22:43.748 3099-3780 /? D / MPEG4Writer:音轨停止 10-03 21:22:43.748 3099-3780 /? E / MPEG4Writer:调用了Stop()但未启动跟踪

此错误几乎是7/10。我无法获得与此错误相关的stackoverflow。 有人可以帮我解决上面问题。谢谢你。

0 个答案:

没有答案