mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
feat: Add concatenate functionality
This commit is contained in:
parent
f79315e0c3
commit
7b19be595c
@ -71,5 +71,7 @@ dependencies {
|
|||||||
annotationProcessor 'com.google.dagger:hilt-compiler:2.46.1'
|
annotationProcessor 'com.google.dagger:hilt-compiler:2.46.1'
|
||||||
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
|
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
|
||||||
|
|
||||||
|
implementation 'com.arthenica:ffmpeg-kit-full:5.1'
|
||||||
|
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||||
}
|
}
|
@ -79,24 +79,19 @@ fun AudioRecorder() {
|
|||||||
Text(text = if (isRecording) "Stop" else "Start")
|
Text(text = if (isRecording) "Stop" else "Start")
|
||||||
}
|
}
|
||||||
if (!isRecording && service != null)
|
if (!isRecording && service != null)
|
||||||
LazyColumn() {
|
Button(
|
||||||
val items = service!!.getRecordingFilePaths().toList()
|
onClick = {
|
||||||
|
val path = service!!.concatenateAudios()
|
||||||
|
|
||||||
items(items.size) {
|
val player = MediaPlayer().apply {
|
||||||
val path = items[it]
|
setDataSource(path)
|
||||||
|
prepare()
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
val player = MediaPlayer().apply {
|
|
||||||
setDataSource(path)
|
|
||||||
prepare()
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text(text = "Play $it")
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
player.start()
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(text = "Convert")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,8 +9,11 @@ import android.os.Build
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
|
import com.arthenica.ffmpegkit.ReturnCode
|
||||||
import kotlinx.coroutines.NonCancellable.start
|
import kotlinx.coroutines.NonCancellable.start
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@ -19,7 +22,7 @@ import java.util.Date
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
const val INTERVAL_DURATION = 30000L
|
const val INTERVAL_DURATION = 10000L
|
||||||
|
|
||||||
class RecorderService: Service() {
|
class RecorderService: Service() {
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
@ -74,6 +77,30 @@ class RecorderService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun concatenateAudios(): String {
|
||||||
|
val paths = getRecordingFilePaths().joinToString("|")
|
||||||
|
val outputFile = "$fileFolder/concatenated.${getFileExtensions()}"
|
||||||
|
val command = "-i \"concat:$paths\" -acodec copy $outputFile"
|
||||||
|
|
||||||
|
val session = FFmpegKit.execute(command)
|
||||||
|
|
||||||
|
if (!ReturnCode.isSuccess(session.returnCode)) {
|
||||||
|
Log.d(
|
||||||
|
"Audio Concatenation",
|
||||||
|
String.format(
|
||||||
|
"Command failed with state %s and rc %s.%s",
|
||||||
|
session.getState(),
|
||||||
|
session.getReturnCode(),
|
||||||
|
session.getFailStackTrace()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
throw Exception("Failed to concatenate audios")
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFile
|
||||||
|
}
|
||||||
|
|
||||||
private fun startNewRecording() {
|
private fun startNewRecording() {
|
||||||
if (!isRecording) {
|
if (!isRecording) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user