旧相机API - 导致unlock()失败的原因是什么?

时间:2017-01-20 07:28:45

标签: android camera

我正在使用MediaRecorderAPI录制视频片段,并且我正在使用已弃用的Camera API。代码如下所示:

var menuLinks = document.querySelectorAll('.link');

for (i=0; i<menuLinks.length; i++) {
  menuLinks[i].addEventListener('click', function(){
    toggleClass(theToggle, 'on');
  });
}

这适用于大多数设备。但是,还有一些其他@TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean prepareVideoRecorder() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE); try { CameraCharacteristics characteristics = manager.getCameraCharacteristics("" + currentCameraId); mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { e.printStackTrace(); } } mMediaRecorder = new MediaRecorder(); mCamera.unlock(); mMediaRecorder.setCamera(mCamera); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mSensorOrientation != null) { int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation(); switch (mSensorOrientation) { case SENSOR_ORIENTATION_DEFAULT_DEGREES: mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); break; case SENSOR_ORIENTATION_INVERSE_DEGREES: mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); break; } } else { if (currentCameraId == 0) { mMediaRecorder.setOrientationHint(90); } else { mMediaRecorder.setOrientationHint(270); } } mMediaRecorder.setMaxDuration(MAX_DURATION_VIDEO); mMediaRecorder.setProfile(CamcorderProfile.get(currentCameraId, CamcorderProfile.QUALITY_HIGH)); mMediaRecorder.setVideoSize(1280, 720); outputFile = VideoUtils.getOutputMediaFile(Constant.MEDIA_TYPE_VIDEO); mFileObserver = new MyFileObserver(outputFile.toString(), FileObserver.ALL_EVENTS); mMediaRecorder.setOutputFile(outputFile.toString()); mListUri.add(VideoUtils.getOutputMediaFileUri(Constant.MEDIA_TYPE_VIDEO)); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); 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; } 会偶尔抛出mCamera.unlock()

我挖掘了源代码并看到了这个:

RuntimeException: unlock failed

我认为是在调用static void android_hardware_Camera_unlock(JNIEnv *env, jobject thiz) { ALOGV("unlock"); sp<Camera> camera = get_native_camera(env, thiz, NULL); if (camera == 0) return; if (camera->unlock() != NO_ERROR) { jniThrowRuntimeException(env, "unlock failed"); } } 时执行的代码。

我的问题是,如果这是解锁相机的代码,那么可能导致mCamera.unlock()返回camera->unlock()以外的内容的原因是什么?

0 个答案:

没有答案