正如标题所说,我有这段代码来准备录音机:
private boolean prepareMediaRecorder(){
myCamera = getCameraInstance();
Camera.Parameters p = myCamera.getParameters();
p.set("orientation", "landscape");
p.set("rotation", 90);
myCamera.setParameters(p);
myCamera.setDisplayOrientation(90);
myCamera.unlock();
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
File tempFile = new File(Environment.getExternalStorageDirectory(), "/rec/temp/video_" + String.valueOf(videoCount) + ".mp4");
mediaRecorder.setOutputFile(tempFile.getPath());
mediaRecorder.setMaxDuration(12500); // Set max duration 11 sec.
mediaRecorder.setMaxFileSize(7000000); // Set max file size 7M
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}
我的表面观点是:
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int weight,
int height) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null){
// preview surface does not exist
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e){
// ignore: tried to stop a non-existent preview
}
// make any resize, rotate or reformatting changes here
// start preview with new settings
try {
myCamera.setDisplayOrientation(90);
mCamera.startPreview();
} catch (Exception e){
}
}
这是使用相机的唯一两个地方(旋转)...... 当录制它很好时,一切都是纵向的,但是当我播放那个视频时它就是风景画。任何人都可以告诉我为什么以及如何解决这个问题?
答案 0 :(得分:2)
使用setOrientationHint(int degrees)http://developer.android.com/reference/android/media/MediaRecorder.html#setOrientationHint(int)
mediaRecorder.setOrientationHint(90); (背面摄像头为90,前置摄像头为270) 在mediaRecorder.prepare();
之前调用它