From 2ca0bd97a572ad2807dda0a407135a043f5aadff Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Mon, 11 Apr 2022 00:17:34 +0800 Subject: [PATCH] set surfaceHolder when not null --- Live/src/main/java/com/frank/live/camera/CameraHelper.java | 6 ++---- app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Live/src/main/java/com/frank/live/camera/CameraHelper.java b/Live/src/main/java/com/frank/live/camera/CameraHelper.java index 728b82e..d050826 100644 --- a/Live/src/main/java/com/frank/live/camera/CameraHelper.java +++ b/Live/src/main/java/com/frank/live/camera/CameraHelper.java @@ -114,7 +114,6 @@ public class CameraHelper implements SurfaceHolder.Callback, Camera.PreviewCallb parameters.setPreviewSize(mWidth, mHeight); } - public void setPreviewDisplay(SurfaceHolder surfaceHolder) { mSurfaceHolder = surfaceHolder; mSurfaceHolder.addCallback(this); @@ -160,7 +159,7 @@ public class CameraHelper implements SurfaceHolder.Callback, Camera.PreviewCallb int index = 0; int ySize = mWidth * mHeight; int uvHeight = mHeight / 2; - //back camera rotate 90 deree + //back camera if (mCameraId == Camera.CameraInfo.CAMERA_FACING_BACK) { for (int i = 0; i < mWidth; i++) { @@ -177,8 +176,7 @@ public class CameraHelper implements SurfaceHolder.Callback, Camera.PreviewCallb bytes[index++] = data[ySize + mWidth * j + i + 1]; } } - } else { - //rotate 90 degree + } else { // front camera for (int i = 0; i < mWidth; i++) { int nPos = mWidth - 1; for (int j = 0; j < mHeight; j++) { 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 c052fe2..392a2a1 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.kt @@ -83,11 +83,10 @@ open class LiveActivity : BaseActivity(), CompoundButton.OnCheckedChangeListener val audioParam = AudioParam(sampleRate, channelConfig, audioFormat, numChannels) // Camera1: SurfaceView Camera2: TextureView livePusher = LivePusherNew(this, videoParam, audioParam, liveView, CameraType.CAMERA2) - var holder :SurfaceHolder ?= null if (liveView is SurfaceView) { - holder = (liveView as SurfaceView).holder + val holder: SurfaceHolder = (liveView as SurfaceView).holder + livePusher!!.setPreviewDisplay(holder) } - livePusher!!.setPreviewDisplay(holder) } private fun registerBroadcast(networkChangeListener: OnNetworkChangeListener) {