mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Properly save concatenated files
This commit is contained in:
parent
9a43afbe3e
commit
0b9bb48fdc
@ -30,6 +30,7 @@ import java.io.File
|
|||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
import java.time.format.DateTimeFormatter.ISO_DATE_TIME
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
@ -100,10 +101,15 @@ class RecorderService: Service() {
|
|||||||
|
|
||||||
fun concatenateFiles(forceConcatenation: Boolean = false): File {
|
fun concatenateFiles(forceConcatenation: Boolean = false): File {
|
||||||
val paths = filePaths.joinToString("|")
|
val paths = filePaths.joinToString("|")
|
||||||
val outputFile = "$fileFolder/${recordingStart!!.format(DateTimeFormatter.ISO_DATE_TIME)}.${settings.fileExtension}"
|
val fileName = recordingStart!!
|
||||||
|
.format(DateTimeFormatter.ISO_DATE_TIME)
|
||||||
|
.toString()
|
||||||
|
.replace(":", "-")
|
||||||
|
.replace(".", "_")
|
||||||
|
val outputFile = File("$fileFolder/$fileName.${settings.fileExtension}")
|
||||||
|
|
||||||
if (File(outputFile).exists() && !forceConcatenation) {
|
if (outputFile.exists() && !forceConcatenation) {
|
||||||
return File(outputFile)
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
val command = "-i \"concat:$paths\" -acodec copy $outputFile"
|
val command = "-i \"concat:$paths\" -acodec copy $outputFile"
|
||||||
@ -124,7 +130,7 @@ class RecorderService: Service() {
|
|||||||
throw Exception("Failed to concatenate audios")
|
throw Exception("Failed to concatenate audios")
|
||||||
}
|
}
|
||||||
|
|
||||||
return File(outputFile)
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAmplitude() {
|
private fun updateAmplitude() {
|
||||||
|
@ -44,6 +44,7 @@ import app.myzel394.locationtest.ui.components.atoms.Pulsating
|
|||||||
import app.myzel394.locationtest.ui.utils.formatDuration
|
import app.myzel394.locationtest.ui.utils.formatDuration
|
||||||
import app.myzel394.locationtest.ui.utils.rememberFileSaverDialog
|
import app.myzel394.locationtest.ui.utils.rememberFileSaverDialog
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import java.io.File
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
@ -51,9 +52,9 @@ import java.time.ZoneId
|
|||||||
@Composable
|
@Composable
|
||||||
fun RecordingStatus(
|
fun RecordingStatus(
|
||||||
service: RecorderService,
|
service: RecorderService,
|
||||||
|
saveFile: (File) -> Unit,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val saveFile = rememberFileSaverDialog("audio/*")
|
|
||||||
|
|
||||||
var now by remember { mutableStateOf(LocalDateTime.now()) }
|
var now by remember { mutableStateOf(LocalDateTime.now()) }
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ import app.myzel394.locationtest.services.RecorderService
|
|||||||
import app.myzel394.locationtest.ui.components.AudioRecorder.atoms.RecordingStatus
|
import app.myzel394.locationtest.ui.components.AudioRecorder.atoms.RecordingStatus
|
||||||
import app.myzel394.locationtest.ui.components.AudioRecorder.atoms.StartRecording
|
import app.myzel394.locationtest.ui.components.AudioRecorder.atoms.StartRecording
|
||||||
import app.myzel394.locationtest.ui.enums.Screen
|
import app.myzel394.locationtest.ui.enums.Screen
|
||||||
|
import app.myzel394.locationtest.ui.utils.rememberFileSaverDialog
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@ -53,6 +54,7 @@ fun AudioRecorder(
|
|||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val saveFile = rememberFileSaverDialog("audio/aac")
|
||||||
var service by remember { mutableStateOf<RecorderService?>(null) }
|
var service by remember { mutableStateOf<RecorderService?>(null) }
|
||||||
val connection = remember {
|
val connection = remember {
|
||||||
object : ServiceConnection {
|
object : ServiceConnection {
|
||||||
@ -78,7 +80,7 @@ fun AudioRecorder(
|
|||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = {
|
||||||
Text(text = "Audio Recorder")
|
Text("Alibi")
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(
|
IconButton(
|
||||||
@ -101,7 +103,7 @@ fun AudioRecorder(
|
|||||||
.padding(padding),
|
.padding(padding),
|
||||||
) {
|
) {
|
||||||
if (isRecording && service != null)
|
if (isRecording && service != null)
|
||||||
RecordingStatus(service = service!!)
|
RecordingStatus(service = service!!, saveFile = saveFile)
|
||||||
else
|
else
|
||||||
StartRecording(connection = connection, service = service)
|
StartRecording(connection = connection, service = service)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package app.myzel394.locationtest.ui.utils
|
|||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -10,22 +12,26 @@ import java.io.File
|
|||||||
fun rememberFileSaverDialog(mimeType: String): ((File) -> Unit) {
|
fun rememberFileSaverDialog(mimeType: String): ((File) -> Unit) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
var file: File? = null
|
var file = remember { mutableStateOf<File?>(null) }
|
||||||
|
|
||||||
val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.CreateDocument(mimeType)) {
|
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument(mimeType)) {
|
||||||
|
println("file")
|
||||||
|
println(file)
|
||||||
it?.let {
|
it?.let {
|
||||||
context.contentResolver.openOutputStream(it)?.use { outputStream ->
|
context.contentResolver.openOutputStream(it)?.use { outputStream ->
|
||||||
file!!.inputStream().use { inputStream ->
|
file.value!!.inputStream().use { inputStream ->
|
||||||
inputStream.copyTo(outputStream)
|
inputStream.copyTo(outputStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file = null
|
file.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
file = it
|
println("eich")
|
||||||
|
println(it)
|
||||||
|
file.value = it
|
||||||
launcher.launch(it.name)
|
launcher.launch(it.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user