检测设备是否存在前置摄像头

照相机,我自己写的代码:

mMediaRecorderVideo=new MediaRecorder();
mCamera=Camera.open();      
mCamera.setDisplayOrientation(90);
mCamera.unlock();
mMediaRecorderVideo.setCamera(mCamera);
mMediaRecorderVideo.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorderVideo.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorderVideo.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

使用设备的默认相机,但是如果有前置相机需要设置,应该怎么检测?谢谢


慕娘9325324
浏览 529回答 2
2回答

慕斯709654

int&nbsp;numCameras=&nbsp;Camera.getNumberOfCameras(); for(int&nbsp;i=0;i<numCameras;i++){ &nbsp;&nbsp;&nbsp;&nbsp;Camera.CameraInfo&nbsp;info&nbsp;=&nbsp;new&nbsp;CameraInfo(); &nbsp;&nbsp;&nbsp;&nbsp;Camera.getCameraInfo(i,&nbsp;info); &nbsp;&nbsp;&nbsp;&nbsp;if(CAMERA_FACING_FRONT&nbsp;==&nbsp;info.facing){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true; &nbsp;&nbsp;&nbsp;&nbsp;} } return&nbsp;false;如果你还要得到前置相机的数量,那么在return中返回i,0返回not found。

眼眸繁星

int&nbsp;cameraId&nbsp;=&nbsp;android.hardware.Camera.getNumberOfCameras();cameraId大于1就是有两个以上的摄像头,打开用open(int id),id为0到cameraId-1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java