I am trying to create my own video application. Work with parameters only in manifest 2.2 (API 8).
Everything is going well, but I do not understand why video in portrait mode is no different from lanscape.
To make a detection of a changed orientation of the device, I use this code in the surfaceChanged () file
if (mCamera != null) { Camera.Parameters p = mCamera.getParameters(); try { mCamera.stopPreview(); } catch (Exception e) { // TODO: handle exception } int previewWidth = 0; int previewHeight = 0; if (mPreviewSize != null) { Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); switch (rotation) { case Surface.ROTATION_0: previewWidth = mPreviewSize.height; previewHeight = mPreviewSize.width; mCamera.setDisplayOrientation(90); break; case Surface.ROTATION_90: previewWidth = mPreviewSize.width; previewHeight = mPreviewSize.height; mCamera.setDisplayOrientation(0); break; case Surface.ROTATION_180: previewWidth = mPreviewSize.height; previewHeight = mPreviewSize.width; mCamera.setDisplayOrientation(270); break; case Surface.ROTATION_270: previewWidth = mPreviewSize.width; previewHeight = mPreviewSize.height; mCamera.setDisplayOrientation(180); break; } p.setPreviewSize(previewWidth, previewHeight); mCamera.setParameters(p); } try { mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (Exception e) { Log.d(TAG, "Cannot start preview.", e); } }
It works like a charm. If I rotate the surface change orientation of the device, causing the Changed surface, where the camera is set to the appropriate DisplayRotation.
The question is how to determine later if the video is captured in either lanscape or portrait mode. When I received all the videos, you are in landscape orientation. This is independent of setDisplayOrientation, which only affects the preview process.
Also, studying the problem, I noticed that if you use the standard application for the camera, it writes a special tag to the video file (see MediaInfo): Rotate: 90 for videos shot in the portrait.
But the MediaRecorder class does not work.
This seems to be a problem. Does anyone have to solve this?
Oleg Karakoz
source share