I am trying to get MediaRecorder to work after an official example, and although I can make the file, it rotates 90 degrees clockwise ...
Now I'm trying to do this in portrait mode and really rotated the preview 90 degrees and blocked it in portrait mode ...
I have no idea how to fix this and get a portrait video, and tried many solutions related to this topic, all to no avail ...
the code:
public class CameraRecorder {
private Camera cam;
private MediaRecorder mMediaRecorder;
private CameraPreview mPreview;
private static Context mContext;
public CameraRecorder(CameraPreview preview, Context context){
mPreview = preview;
cam = mPreview.getCamera();
mContext = context;
}
public boolean prep(){
mMediaRecorder = new MediaRecorder();
cam.unlock();
mMediaRecorder.setCamera(cam);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mMediaRecorder.setOutputFile(getOutputMediaFile().toString());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d("Exception", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d("Exception", "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (Exception e) {
Log.d("Exception", "Exception preparing MediaRecorder: " + e.getMessage());
return false;
}
return true;
}
public static File getOutputMediaFile(){
File mediaFile;
mediaFile = new File(mContext.getCacheDir() + File.separator + "vid.mp4");
return mediaFile;
}
public void releaseMediaRecorder(){
if (mMediaRecorder != null) {
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
cam.lock();
}
}
public void startRecording(){
mMediaRecorder.start();
}
public void stopRecording(){
try {
mMediaRecorder.stop();
releaseMediaRecorder();
cam.lock();
} catch (Exception e) {
Log.d("Exception","Exiting with exception: " + e.getMessage());
}
}
}
- ( , " ", )...
-, , ( , , )
, !