fix: Properly cleanup recordings

This commit is contained in:
Myzel394 2023-12-09 10:37:45 +01:00
parent 3cba3382f3
commit d79aabab50
No known key found for this signature in database
GPG Key ID: 50098FCA22080F0F
2 changed files with 8 additions and 68 deletions

View File

@ -54,12 +54,16 @@ fun RecorderEventsHandler(
settings.audioRecorderSettings.getMimeType()
) {
if (settings.deleteRecordingsImmediately) {
audioRecorder.batchesFolder!!.deleteRecordings()
videoRecorder.batchesFolder!!.deleteRecordings()
runCatching {
audioRecorder.batchesFolder?.deleteRecordings()
}
runCatching {
videoRecorder.batchesFolder?.deleteRecordings()
}
}
if (!audioRecorder.batchesFolder!!.hasRecordingsAvailable()
|| !videoRecorder.batchesFolder!!.hasRecordingsAvailable()
if (audioRecorder.batchesFolder?.hasRecordingsAvailable() == false
&& videoRecorder.batchesFolder?.hasRecordingsAvailable() == false
) {
scope.launch {
dataStore.updateData {

View File

@ -1,64 +0,0 @@
package app.myzel394.alibi.ui.screens
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.models.VideoRecorderModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@SuppressLint("NewApi")
@Composable
fun POCVideo(
videoRecorder: VideoRecorderModel,
settings: AppSettings,
) {
val context = LocalContext.current
var started by rememberSaveable {
mutableStateOf(false)
}
val scope = rememberCoroutineScope()
Box(
modifier = Modifier
.fillMaxSize()
.padding(64.dp)
) {
Button(onClick = {
if (!started) {
videoRecorder.startRecording(context, settings)
} else {
scope.launch {
val information = videoRecorder.recorderService!!.getRecordingInformation()
val batchesFolder = videoRecorder.batchesFolder!!
videoRecorder.stopRecording(context)
batchesFolder.concatenate(
recordingStart = information.recordingStart,
extension = information.fileExtension,
disableCache = true,
)
}
}
started = !started
}) {
Text("Start")
}
}
}