Skip to content

Commit ab4a919

Browse files
MHShettythestinger
authored andcommitted
Enhance startRecording function to handle edge cases
where there could be multiple calls to the function
1 parent 64f9f1a commit ab4a919

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class VideoCapturer(private val mActivity: MainActivity) {
150150
fun startRecording() {
151151
if (camConfig.camera == null) return
152152
val recorder = camConfig.videoCapture?.output ?: return
153+
if (isRecording) return
154+
isRecording = true
153155

154156
val dateString = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
155157
val fileName = VIDEO_NAME_PREFIX + dateString + videoFileFormat
@@ -163,6 +165,7 @@ class VideoCapturer(private val mActivity: MainActivity) {
163165
includeAudio = true
164166
} else {
165167
ctx.restartRecordingWithMicPermission()
168+
isRecording = false
166169
return
167170
}
168171
}
@@ -175,6 +178,7 @@ class VideoCapturer(private val mActivity: MainActivity) {
175178
camConfig.onStorageLocationNotFound()
176179
}
177180
ctx.showMessage(R.string.unable_to_access_output_file)
181+
isRecording = false
178182
return
179183
}
180184

@@ -186,8 +190,6 @@ class VideoCapturer(private val mActivity: MainActivity) {
186190

187191
beforeRecordingStarts()
188192

189-
isRecording = true
190-
191193
camConfig.mPlayer.playVRStartSound(handler) {
192194

193195
recording = pendingRecording.start(ctx.mainExecutor) { event ->

0 commit comments

Comments
 (0)