fix some video rotation checks

This commit is contained in:
tibbi 2017-03-26 12:05:38 +02:00
parent 0bead6f1fb
commit 9cca79877b
2 changed files with 9 additions and 18 deletions

View File

@ -535,7 +535,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
}
mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface)
val rotation = mActivity.getMediaRotation(mCurrCameraId)
val rotation = getVideoRotation()
mInitVideoRotation = rotation
mRecorder!!.setOrientationHint(rotation)
@ -565,10 +565,15 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
return mIsRecording
}
private fun getVideoRotation(): Int {
val deviceRot = MainActivity.mOrientation.compensateDeviceRotation(mCurrCameraId)
val previewRot = mActivity.getPreviewRotation(mCurrCameraId)
return (deviceRot + previewRot) % 360
}
private fun startRecording() {
if (mInitVideoRotation != mActivity.getFinalRotation(mCurrCameraId, MainActivity.mOrientation)) {
cleanupRecorder()
initRecorder()
if (mInitVideoRotation != getVideoRotation()) {
}
try {

View File

@ -19,20 +19,6 @@ fun Activity.getPreviewRotation(cameraId: Int): Int {
return result % 360
}
fun Activity.getMediaRotation(cameraId: Int): Int {
val degrees = getDeviceRotationDegrees()
val info = getCameraInfo(cameraId)
return if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
(360 + info.orientation + degrees) % 360
} else
(360 + info.orientation - degrees) % 360
}
fun Activity.getFinalRotation(currCameraId: Int, deviceOrientation: Int): Int {
var rotation = getMediaRotation(currCameraId)
return rotation % 360
}
fun Activity.getDeviceRotationDegrees() = when (windowManager.defaultDisplay.rotation) {
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180