I'm trying to make a custom camera activity. Everything works great until the MediaRecorder starts recording a video. The preview stretches horizontally without an obvious reason as below. I have tried changing the preview size and several suggestions but I couldn't find a working solution. Any Ideas please !!
note: I'm using TextureView object.
start camera
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mST = surface;
try {
mCamera.setDisplayOrientation(90);
mCamera.setPreviewTexture(mST);
mCamera.startPreview();
isReleased = false;
}catch(Exception e){}
//startVideoPreview();
}
start media recorder
private boolean prepareMediaRecorder() {
mediaRecorder = new MediaRecorder();
mCamera.unlock();
mediaRecorder.setCamera(mCamera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setProfile(CamcorderProfile.get(camId, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH));
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
mediaRecorder.setMaxDuration(30000); //set maximum duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); //set maximum file size 50M
mediaRecorder.setPreviewDisplay(new Surface(mTextureView.getSurfaceTexture()));
mediaRecorder.setOutputFile(Environment.getExternalStorageDirectory() + "/tempVid.mp4");
if(camId == Camera.CameraInfo.CAMERA_FACING_BACK){
mediaRecorder.setOrientationHint(90);
}else{
mediaRecorder.setOrientationHint(270);
}
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}
thank you so much