修复开播图片后摄像头卡住问题

This commit is contained in:
zlzw 2024-09-13 14:26:32 +08:00
parent a454a97c58
commit d63cba7db1
2 changed files with 35 additions and 10 deletions

View File

@ -5,13 +5,16 @@ import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.camera2.CameraManager;
import android.net.Uri;
import android.text.TextUtils;
import android.view.SurfaceView;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;
import com.blankj.utilcode.util.LogUtils;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.bean.SwTokenModel;
@ -69,6 +72,7 @@ public class SWManager extends BaseCacheManager {
private ImageTrackOptions imageTrackOptions = null;
private onDrPkJoinSuccessListener onDrPkJoinSuccessListener;
String openCameraId = "1";
public void setOnDrPkJoinSuccessListener(SWManager.onDrPkJoinSuccessListener onDrPkJoinSuccessListener) {
this.onDrPkJoinSuccessListener = onDrPkJoinSuccessListener;
@ -253,7 +257,20 @@ public class SWManager extends BaseCacheManager {
*/
public void switchCamera() {
if (mRtcEngine != null) {
mRtcEngine.switchCamera();
if (openCameraId.equals("0")) {
mRtcEngine.switchCamera("1");
openCameraId = "1";
} else {
mRtcEngine.switchCamera("0");
openCameraId = "0";
}
}
}
public void resetCamera() {
LogUtils.e("重置摄像头", openCameraId);
if (mRtcEngine != null && !TextUtils.isEmpty(openCameraId)) {
mRtcEngine.switchCamera(openCameraId);
}
}
@ -525,6 +542,9 @@ public class SWManager extends BaseCacheManager {
});
}
public void release() {
}
public interface onRtcEngineListener {
void onOpenSuccess(String channel, int uid);

View File

@ -504,8 +504,9 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX
public void onResume() {
mPaused = false;
Log.i("摄像头", "onResume: " + isNeedOpenCamera);
swManager.resetCamera();
if (isNeedOpenCamera) {
RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback<Boolean>() {
/*RCRTCEngine.getInstance().getDefaultVideoStream().startCamera(new IRCRTCResultDataCallback<Boolean>() {
@Override
public void onSuccess(Boolean data) {
//设置摄像头最大缩放比例
@ -519,7 +520,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX
public void onFailed(RTCErrorCode errorCode) {
Log.i("摄像头", "onFailed: 打开摄像头失败 " + errorCode);
}
});
});*/
}
}
@ -550,6 +551,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX
super.release();
Bus.getOff(this);
onDestroy();
SWManager.get().release();
LiveHttpUtil.cancel(LiveHttpConsts.LINK_MIC_TX_MIX_STREAM);
rtcRoom = null;
}
@ -676,8 +678,11 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder implements ITX
public interface onDrPkJoinSuccessListener {
void joinSuccess1();
void joinSuccess2();
void joinSuccess3();
void joinSuccess4();
}