From 3c290102ca0d1d312a9fabcc1e31618598b66a47 Mon Sep 17 00:00:00 2001 From: Jianing Zhang Date: Thu, 22 Oct 2020 20:42:24 +0200 Subject: [PATCH] fix(recorder): make sure onVideoFileReady could only be called once --- .../gpuv/camerarecorder/GPUCameraRecorder.java | 12 ++++++++++-- .../gpuv/camerarecorder/capture/MediaEncoder.java | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/GPUCameraRecorder.java b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/GPUCameraRecorder.java index ff12639..aa4a343 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/GPUCameraRecorder.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/GPUCameraRecorder.java @@ -189,6 +189,8 @@ private void destroyPreview() { private final MediaEncoder.MediaEncoderListener mediaEncoderListener = new MediaEncoder.MediaEncoderListener() { private boolean videoStopped; private boolean audioStopped; + private boolean videoExitReady; + private boolean audioExitReady; @Override public void onPrepared(final MediaEncoder encoder) { @@ -221,8 +223,14 @@ public void onStopped(final MediaEncoder encoder) { } @Override - public void onExit() { - if (videoStopped && audioStopped) { + public void onExit(final MediaEncoder encoder) { + if (encoder instanceof MediaVideoEncoder && videoStopped) { + videoExitReady = true; + } + if (encoder instanceof MediaAudioEncoder && audioStopped) { + audioExitReady = true; + } + if (videoExitReady && audioExitReady) { cameraRecordListener.onVideoFileReady(); } } diff --git a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/MediaEncoder.java b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/MediaEncoder.java index c0244cd..2a64f29 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/MediaEncoder.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/MediaEncoder.java @@ -20,7 +20,7 @@ public interface MediaEncoderListener { void onStopped(MediaEncoder encoder); - void onExit(); + void onExit(MediaEncoder encoder); } protected final Object sync = new Object(); @@ -145,7 +145,7 @@ public void run() { requestStop = true; isCapturing = false; } - listener.onExit(); + listener.onExit(this); } /*