Skip to content

Commit da10fcf

Browse files
committed
Remove unused videos created on setup
1 parent 562f5f8 commit da10fcf

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

app/src/main/java/com/googleresearch/capturesync/ImageMetadataSynchronizer.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import androidx.annotation.NonNull;
3232

33+
import java.io.File;
3334
import java.util.ArrayList;
3435
import java.util.LinkedList;
3536
import java.util.List;
@@ -392,13 +393,18 @@ public void onCaptureCompleted(
392393
@Override
393394
public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, int sequenceId, long frameNumber) {
394395
super.onCaptureSequenceCompleted(session, sequenceId, frameNumber);
395-
Log.v(TAG, "YAAAY I've completed succesfully");
396396
if (context.getLastVideoSeqId() != null && sequenceId == context.getLastVideoSeqId() && context.getLogger() != null) {
397397
context.getMediaRecorder().stop();
398-
// mLogger.close();
399-
// mLogger = null;
398+
399+
if (context.isVideoRecording()) {
400+
context.setVideoRecording(false);
401+
} else {
402+
// MediaRecorder created an empty video on preview, should perform a cleanup
403+
context.deleteUnusedVideo();
404+
}
405+
400406
context.getMediaRecorder().reset();
401-
context.setVideoRecording(false);
407+
402408
context.getLogger().close();
403409
context.setLogger(null);
404410
}

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import java.util.Date;
8080
import java.util.List;
8181
import java.util.Locale;
82-
import java.util.concurrent.Future;
8382
import java.util.concurrent.FutureTask;
8483
import java.util.stream.Collectors;
8584

@@ -95,6 +94,21 @@ public class MainActivity extends Activity {
9594
private String lastTimeStamp;
9695
private PeriodCalculator periodCalculator;
9796

97+
public String getLastVideoPath() {
98+
return lastVideoPath;
99+
}
100+
101+
public void deleteUnusedVideo() {
102+
String videoPath = getLastVideoPath();
103+
File videoFile = new File(videoPath);
104+
boolean result = videoFile.delete();
105+
if (!result) {
106+
Log.d(TAG, "Video file could not be deleted");
107+
}
108+
}
109+
110+
private String lastVideoPath;
111+
98112
public Integer getLastVideoSeqId() {
99113
return lastVideoSeqId;
100114
}
@@ -942,6 +956,7 @@ private void createRecorderSurface() throws IOException {
942956
MediaRecorder recorder = setUpMediaRecorder(surface, false);
943957
recorder.prepare();
944958
recorder.release();
959+
deleteUnusedVideo();
945960
}
946961

947962
private MediaRecorder setUpMediaRecorder(Surface surface) throws IOException {
@@ -959,8 +974,8 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput)
959974
* set output file in media recorder
960975
*/
961976

962-
String currentPath = getOutputMediaFilePath();
963-
recorder.setOutputFile(currentPath);
977+
lastVideoPath = getOutputMediaFilePath();
978+
recorder.setOutputFile(lastVideoPath);
964979

965980
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
966981
recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

0 commit comments

Comments
 (0)