我已经制作了一个应用程序,我正在使用MediaRecorder捕获视频。但是当设备上的预览开始时,图像似乎正在拉伸我刚刚在这里或谷歌上完成了所有相关问题,但没有获得成功。这是我的代码。
video.xml
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" />
Video.java文件配置
public void startRecording() {
try {
if(some codition){
// recording call.
setCameraDisplayOrientaion();
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder
.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioEncodingBitRate(16);
mediaRecorder.setAudioSamplingRate(44100);
CamcorderProfile profile = CamcorderProfile.QUALITY_1080P == CamcorderProfile.QUALITY_HIGH
|| CamcorderProfile
.hasProfile(CamcorderProfile.QUALITY_480P) ? CamcorderProfile
.get(cameraId, CamcorderProfile.QUALITY_480P)
: CamcorderProfile.get(cameraId,
CamcorderProfile.QUALITY_HIGH);
profile.videoFrameRate = 15;
profile.videoBitRate = 150000;
profile.audioBitRate = 12200;
mediaRecorder.setProfile(profile);
mediaRecorder.setOutputFile(string);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (Exception e) {
Log.e(ResponseActivity.class.toString(), e.getMessage());
releaseMediaRecorder();
}
} else {
mediaRecorder = new MediaRecorder();
setCameraDisplayOrientaion();
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setAudioEncodingBitRate(16);
mediaRecorder.setAudioSamplingRate(44100);
CamcorderProfile profile = CamcorderProfile.QUALITY_1080P == CamcorderProfile.QUALITY_HIGH
|| CamcorderProfile
.hasProfile(CamcorderProfile.QUALITY_480P) ? CamcorderProfile
.get(cameraId, CamcorderProfile.QUALITY_480P)
: CamcorderProfile.get(cameraId,
CamcorderProfile.QUALITY_HIGH);
profile.videoFrameRate = videoFrameRate;
profile.videoBitRate = videoBitrate;
profile.audioBitRate = audioBitrate;
mediaRecorder.setProfile(profile);
mediaRecorder.setOutputFile(fullQuestionPath);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (Exception e) {
Log.e(ResponseActivity.class.toString(), e.getMessage());
releaseMediaRecorder();
}
}
} catch (Exception e) {
}
}
请告诉我这里需要更改的配置,任何帮助都会很明显。