reinitialize the recorder if the device rotation changes while not recording

This commit is contained in:
tibbi 2017-03-26 17:28:22 +02:00
parent 10282d36ba
commit fc4bd98e68
2 changed files with 7 additions and 7 deletions

View File

@ -54,7 +54,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private var mWasZooming = false private var mWasZooming = false
private var mLastClickX = 0 private var mLastClickX = 0
private var mLastClickY = 0 private var mLastClickY = 0
private var mInitVideoRotation = 0
private var mCurrCameraId = 0 private var mCurrCameraId = 0
private var mMaxZoom = 0 private var mMaxZoom = 0
} }
@ -366,7 +365,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} catch (e: IOException) { } catch (e: IOException) {
Log.e(TAG, "surfaceCreated IOException " + e.message) Log.e(TAG, "surfaceCreated IOException " + e.message)
} }
} }
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
@ -517,7 +515,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface) mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface)
val rotation = getVideoRotation() val rotation = getVideoRotation()
mInitVideoRotation = rotation
mRecorder!!.setOrientationHint(rotation) mRecorder!!.setOrientationHint(rotation)
try { try {
@ -580,11 +577,14 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
return (deviceRot + previewRot) % 360 return (deviceRot + previewRot) % 360
} }
private fun startRecording() { fun deviceOrientationChanged() {
if (mInitVideoRotation != getVideoRotation()) { if (mIsVideoMode && !mIsRecording) {
mRecorder = null
initRecorder()
} }
}
private fun startRecording() {
try { try {
mCamera!!.unlock() mCamera!!.unlock()
toggleShutterSound(true) toggleShutterSound(true)
@ -596,7 +596,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
Log.e(TAG, "toggleRecording " + e.message) Log.e(TAG, "toggleRecording " + e.message)
releaseCamera() releaseCamera()
} }
} }
private fun stopRecording() { private fun stopRecording() {

View File

@ -498,6 +498,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho
else -> 0 else -> 0
} }
mPreview!!.deviceOrientationChanged()
animateViews(degrees) animateViews(degrees)
mLastHandledOrientation = mOrientation mLastHandledOrientation = mOrientation
} }