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