diff --git a/Live/src/main/java/com/frank/live/camera/Camera2Helper.java b/Live/src/main/java/com/frank/live/camera/Camera2Helper.java index d13cfde..77c7354 100644 --- a/Live/src/main/java/com/frank/live/camera/Camera2Helper.java +++ b/Live/src/main/java/com/frank/live/camera/Camera2Helper.java @@ -86,32 +86,32 @@ public class Camera2Helper { start(); } - private int getCameraOri(int rotation, String cameraId) { - int degrees = rotation * 90; + private int getCameraOrientation(int rotation, String cameraId) { + int degree = rotation * 90; switch (rotation) { case Surface.ROTATION_0: - degrees = 0; + degree = 0; break; case Surface.ROTATION_90: - degrees = 90; + degree = 90; break; case Surface.ROTATION_180: - degrees = 180; + degree = 180; break; case Surface.ROTATION_270: - degrees = 270; + degree = 270; break; default: break; } int result; if (CAMERA_ID_FRONT.equals(cameraId)) { - result = (mSensorOrientation + degrees) % 360; + result = (mSensorOrientation + degree) % 360; result = (360 - result) % 360; } else { - result = (mSensorOrientation - degrees + 360) % 360; + result = (mSensorOrientation - degree + 360) % 360; } - Log.i(TAG, "getCameraOri: " + rotation + " " + result + " " + mSensorOrientation); + Log.i(TAG, "getCameraOrientation, result=" + result); return result; } @@ -120,19 +120,19 @@ public class Camera2Helper { @Override public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { - Log.i(TAG, "onSurfaceTextureAvailable: "); + Log.i(TAG, "onSurfaceTextureAvailable..."); openCamera(); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { - Log.i(TAG, "onSurfaceTextureSizeChanged: "); + Log.i(TAG, "onSurfaceTextureSizeChanged, width=" + width + "--height=" + height); configureTransform(width, height); } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) { - Log.i(TAG, "onSurfaceTextureDestroyed: "); + Log.i(TAG, "onSurfaceTextureDestroyed..."); return true; } @@ -151,7 +151,7 @@ public class Camera2Helper { mCameraDevice = cameraDevice; createCameraPreviewSession(); if (camera2Listener != null) { - camera2Listener.onCameraOpened(mPreviewSize, getCameraOri(rotation, mCameraId)); + camera2Listener.onCameraOpened(mPreviewSize, getCameraOrientation(rotation, mCameraId)); } } @@ -179,6 +179,7 @@ public class Camera2Helper { } }; + private final CameraCaptureSession.StateCallback mCaptureStateCallback = new CameraCaptureSession.StateCallback() { @Override @@ -286,7 +287,7 @@ public class Camera2Helper { context = null; } - private void setUpCameraOutputs(CameraManager cameraManager) { + private void setUpCameraOutput(CameraManager cameraManager) { try { if (configCameraParams(cameraManager, specificCameraId)) { return; @@ -330,7 +331,7 @@ public class Camera2Helper { private void openCamera() { CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); - setUpCameraOutputs(cameraManager); + setUpCameraOutput(cameraManager); configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { @@ -463,7 +464,6 @@ public class Camera2Helper { } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } - Log.i(TAG, "configureTransform: " + getCameraOri(rotation, mCameraId) + " " + rotation * 90); mTextureView.setTransform(matrix); } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e766a9d..172c5a6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,7 +20,6 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" - android:screenOrientation="landscape" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:name"> @@ -39,7 +38,7 @@ + android:configChanges="orientation" /> diff --git a/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt index 392a2a1..5b235bc 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt @@ -2,6 +2,7 @@ package com.frank.ffmpeg.activity import android.annotation.SuppressLint import android.content.IntentFilter +import android.content.res.Configuration import android.media.AudioFormat import android.net.ConnectivityManager import android.os.Bundle @@ -153,6 +154,11 @@ open class LiveActivity : BaseActivity(), CompoundButton.OnCheckedChangeListener } } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + Log.i(TAG, "onConfigurationChanged, orientation=" + newConfig.orientation) + } + companion object { private val TAG = LiveActivity::class.java.simpleName