From 80b0a2f2cfa3374fb2e4c9688e31b10a5317338c Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Thu, 7 Mar 2024 10:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AA=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/MicroPhoto.cpp | 12 +++++++--- .../xypower/mpapp/video/VideoFragment.java | 23 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 31b74541..da3ba82c 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -627,13 +627,19 @@ Java_com_xypower_mpapp_MicroPhotoService_recordingFinished( IDevice* dev = pTerminal->GetDevice(); if (dev != NULL) { - const char *pathStr = env->GetStringUTFChars(path, 0); + const char *pathStr = NULL; + if (path != NULL) + { + pathStr = env->GetStringUTFChars(path, 0); + } // camera->Open(pathStr, fileNameStr); unsigned long photoId = videoId; ((CPhoneDevice *)dev)->OnVideoReady(result != JNI_FALSE, pathStr, photoId); - - env->ReleaseStringUTFChars(path, pathStr); + if (path != NULL) + { + env->ReleaseStringUTFChars(path, pathStr); + } } } diff --git a/app/src/main/java/com/xypower/mpapp/video/VideoFragment.java b/app/src/main/java/com/xypower/mpapp/video/VideoFragment.java index a0e48727..0b01f18f 100644 --- a/app/src/main/java/com/xypower/mpapp/video/VideoFragment.java +++ b/app/src/main/java/com/xypower/mpapp/video/VideoFragment.java @@ -569,14 +569,16 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med manager.openCamera(Integer.toString(mCameraId), mStateCallback, null); } catch (CameraAccessException e) { // Toast.makeText(activity, "Cannot access the camera.", Toast.LENGTH_SHORT).show(); + broadcastVideoFile(false, mNextVideoAbsolutePath); activity.finish(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. - ErrorDialog.newInstance(getString(R.string.camera_error)) - .show(getChildFragmentManager(), FRAGMENT_DIALOG); - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock camera opening."); + broadcastVideoFile(false, mNextVideoAbsolutePath); + activity.finish(); + } catch (Exception e) { + broadcastVideoFile(false, mNextVideoAbsolutePath); + activity.finish(); } } @@ -592,8 +594,9 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med mMediaRecorder.release(); mMediaRecorder = null; } - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted while trying to lock camera closing."); + } catch (Exception e) { + broadcastVideoFile(false, mNextVideoAbsolutePath); + getActivity().finish(); } finally { mCameraOpenCloseLock.release(); } @@ -655,6 +658,9 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med } catch (CameraAccessException e) { e.printStackTrace(); } + catch (Exception e) { + e.printStackTrace(); + } } private void setUpCaptureRequestBuilder(CaptureRequest.Builder builder) { @@ -824,6 +830,11 @@ public class VideoFragment extends Fragment implements View.OnClickListener, Med }, mBackgroundHandler); } catch (CameraAccessException | IOException e) { e.printStackTrace(); + broadcastVideoFile(false, ""); + } + catch (Exception e) { + e.printStackTrace(); + broadcastVideoFile(false, ""); } }