mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
current stand: Added symlinks
This commit is contained in:
parent
6948e11fca
commit
d69bc7f4b1
@ -1,7 +1,11 @@
|
||||
package app.myzel394.alibi.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.system.Os
|
||||
import android.util.Log
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import app.myzel394.alibi.db.RecordingInformation
|
||||
import app.myzel394.alibi.ui.RECORDER_SUBFOLDER_NAME
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
@ -12,16 +16,12 @@ import java.time.format.DateTimeFormatter
|
||||
data class AudioRecorderExporter(
|
||||
val recording: RecordingInformation,
|
||||
) {
|
||||
val filePaths: List<File>
|
||||
get() =
|
||||
File(recording.folderPath).listFiles()?.filter {
|
||||
val name = it.nameWithoutExtension
|
||||
private fun getFilePaths(context: Context): List<File> =
|
||||
getFolder(context).listFiles()?.filter {
|
||||
val name = it.nameWithoutExtension
|
||||
|
||||
name.toIntOrNull() != null
|
||||
}?.toList() ?: emptyList()
|
||||
|
||||
val hasRecordingAvailable: Boolean
|
||||
get() = filePaths.isNotEmpty()
|
||||
name.toIntOrNull() != null
|
||||
}?.toList() ?: emptyList()
|
||||
|
||||
private fun stripConcatenatedFileToExactDuration(
|
||||
outputFile: File
|
||||
@ -50,8 +50,14 @@ data class AudioRecorderExporter(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun concatenateFiles(forceConcatenation: Boolean = false): File {
|
||||
val paths = filePaths.joinToString("|")
|
||||
suspend fun concatenateFiles(
|
||||
context: Context,
|
||||
forceConcatenation: Boolean = false,
|
||||
): File {
|
||||
val filePaths = getFilePaths(context)
|
||||
val paths = filePaths.joinToString("|") {
|
||||
it.path
|
||||
}
|
||||
val fileName = recording.recordingStart
|
||||
.format(DateTimeFormatter.ISO_DATE_TIME)
|
||||
.toString()
|
||||
@ -97,14 +103,6 @@ data class AudioRecorderExporter(
|
||||
return outputFile
|
||||
}
|
||||
|
||||
suspend fun cleanupFiles() {
|
||||
filePaths.forEach {
|
||||
runCatching {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getFolder(context: Context) = File(context.filesDir, RECORDER_SUBFOLDER_NAME)
|
||||
|
||||
@ -114,5 +112,29 @@ data class AudioRecorderExporter(
|
||||
|
||||
fun hasRecordingsAvailable(context: Context) =
|
||||
getFolder(context).listFiles()?.isNotEmpty() ?: false
|
||||
|
||||
fun linkBatches(context: Context, batchesFolder: Uri, destinationFolder: File) {
|
||||
val folder = DocumentFile.fromTreeUri(
|
||||
context,
|
||||
batchesFolder,
|
||||
)!!
|
||||
|
||||
destinationFolder.mkdirs()
|
||||
|
||||
folder.listFiles().forEach {
|
||||
if (it.name?.substringBeforeLast(".")?.toIntOrNull() == null) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
println(
|
||||
"symlinking ${folder.uri}/${it.name} to ${destinationFolder.absolutePath}/${it.name}"
|
||||
)
|
||||
|
||||
Os.symlink(
|
||||
"${folder.uri}/${it.name}",
|
||||
"${destinationFolder.absolutePath}/${it.name}",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -58,8 +58,10 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
MediaRecorder()
|
||||
}.apply {
|
||||
// Setting file path
|
||||
/*
|
||||
if (customOutputFolder == null) {
|
||||
val newFilePath = "${defaultOutputFolder}/$counter.${settings!!.fileExtension}"
|
||||
|
||||
setOutputFile(newFilePath)
|
||||
} else {
|
||||
customOutputFolder!!.createFile(
|
||||
"audio/${settings!!.fileExtension}",
|
||||
@ -70,15 +72,6 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
setOutputFile(fileDescriptor)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
val newFilePath = "${defaultOutputFolder}/$counter.${settings!!.fileExtension}"
|
||||
|
||||
println("newfile path: ${newFilePath}")
|
||||
|
||||
setOutputFile(newFilePath)
|
||||
println("outputformat eta: ${settings!!.outputFormat}")
|
||||
setOutputFormat(settings!!.outputFormat)
|
||||
|
||||
// Audio Source is kinda strange, here are my experimental findings using a Pixel 7 Pro
|
||||
// and Redmi Buds 3 Pro:
|
||||
@ -87,6 +80,8 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
// - VOICE_COMMUNICATION: Uses the bottom microphone of the phone (17)
|
||||
// - DEFAULT: Uses the bottom microphone of the phone (17)
|
||||
setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
println("outputformat eta: ${settings!!.outputFormat}")
|
||||
setOutputFormat(settings!!.outputFormat)
|
||||
|
||||
setAudioEncoder(settings!!.encoder)
|
||||
setAudioEncodingBitRate(settings!!.bitRate)
|
||||
|
@ -28,6 +28,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.navigation.NavController
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.organisms.RecordingStatus
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.molecules.StartRecording
|
||||
@ -94,11 +96,19 @@ fun AudioRecorderScreen(
|
||||
delay(100)
|
||||
|
||||
try {
|
||||
if (settings.audioRecorderSettings.saveFolder != null) {
|
||||
AudioRecorderExporter.linkBatches(
|
||||
context,
|
||||
settings.audioRecorderSettings.saveFolder.toUri(),
|
||||
AudioRecorderExporter.getFolder(context),
|
||||
)
|
||||
}
|
||||
|
||||
val file = AudioRecorderExporter(
|
||||
audioRecorder.recorderService?.getRecordingInformation()
|
||||
?: settings.lastRecording
|
||||
?: throw Exception("No recording information available"),
|
||||
).concatenateFiles()
|
||||
).concatenateFiles(context)
|
||||
|
||||
saveFile(file, file.name)
|
||||
} catch (error: Exception) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user