TencentCloud / TIMSDK

Tencent Cloud Chat features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication.
https://trtc.io/products/chat
2.57k stars 2.76k forks source link

【Android】-【7.6.5011】:【拍照按钮快速连续点击会导致RuntimeException】 #1381

Open tashuodeni opened 9 months ago

tashuodeni commented 9 months ago

issue标题:

【Android】-【7.6.5011】:【拍照按钮快速连续点击会导致RuntimeException】 issue内容:

【当前现象】:聊天界面点击拍照,进入CameraActivity,快速连续点击拍照按钮会导致 java.lang.RuntimeException: takePicture failed 【集成包】:TUIKIT 【机型】:魅族18Pro 【之前版本有无此问题】:应该一直存在 【有无日志或者描述、截图】: java.lang.RuntimeException: takePicture failed at android.hardware.Camera.native_takePicture(Native Method) at android.hardware.Camera.takePicture(Camera.java:1630) at android.hardware.Camera.takePicture(Camera.java:1571) at com.tencent.qcloud.tuikit.tuichat.component.camera.view.CameraInterface.takePicture(CameraInterface.java:327) at com.tencent.qcloud.tuikit.tuichat.component.camera.state.PreviewState.capture(PreviewState.java:49) at com.tencent.qcloud.tuikit.tuichat.component.camera.state.CameraMachine.capture(CameraMachine.java:75) at com.tencent.qcloud.tuikit.tuichat.component.camera.view.CameraView$2.takePictures(CameraView.java:155) at com.tencent.qcloud.tuikit.tuichat.component.camera.view.CaptureLayout$2.takePictures(CaptureLayout.java:134) at com.tencent.qcloud.tuikit.tuichat.component.camera.view.CaptureButton$2.onAnimationEnd(CaptureButton.java:220) at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:600) at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1333) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1575) at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:326) at android.animation.AnimationHandler.-$$Nest$mdoAnimationFrame(Unknown Source:0) at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:86) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1439) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1449) at android.view.Choreographer.doCallbacks(Choreographer.java:1097) at android.view.Choreographer.doFrame(Choreographer.java:1023) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1414) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:8045) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

------------------------- 修复方案 ------------------------- 可在PreviewState类中添加标志位

class PreviewState implements State {
    private boolean capturing = false;

    @Override
    public void capture() {
        TUIChatLog.i(TAG, "capture");

        if (capturing) {
            return;
        }

        capturing = true;
        CameraInterface.getInstance().takePicture(new CameraInterface.TakePictureCallback() {
            @Override
            public void captureResult(Bitmap bitmap, boolean isVertical) {
                capturing = false;
                String path = FileUtil.generateImageFilePath();
                boolean result = FileUtil.saveBitmap(path, bitmap);
                if (!result) {
                    TUIChatLog.e(TAG, "take picture save bitmap failed");
                }
                machine.getCameraView().showPicture(bitmap, isVertical);
                machine.getBrowserPictureState().setDataPath(path);
                machine.setState(machine.getBrowserPictureState());
            }
        });
    }
}
tashuodeni commented 9 months ago

https://github.com/TencentCloud/TIMSDK/assets/22451098/1cce8b64-d6a6-487a-9a43-c36a59d66f3c

复现视频

tashuodeni commented 9 months ago

WX20231228-200311@2x 错误堆栈