如何使用表面视图打开前置摄像头,并在Android 3.1中录制视频?任何人都可以提供示例代码吗?
答案 0 :(得分:5)
这应该有效,假设你已经创建了表面:
int cameraType = 1; // front
camera = Camera.open(cameraType);
m_recorder = new MediaRecorder();
m_recorder.setPreviewDisplay(m_BeMeSurface);
m_recorder.setCamera(camera);
m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
m_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
m_recorder.setMaxDuration((int) MAX_TIME);
m_recorder.setOnInfoListener(m_BeMeSelf);
m_recorder.setVideoSize(320, 240);
m_recorder.setVideoFrameRate(15);
m_recorder.setOutputFile(m_path);
m_recorder.prepare();
m_recorder.start();
请注意,并非所有相机硬件都支持前置摄像头视频录制。在这种情况下,使用后置摄像头。调用此api以找出哪个video recording sizes可用
答案 1 :(得分:1)
试试这个
camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
camera.setDisplayOrientation(90);
camera.unlock();
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mediaRecorder.setProfile(camcorderProfile_HQ);
mediaRecorder.setOutputFile(getOutputMediaFile(2).toString());
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M