mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
feat: Fetch duration on recording start
This commit is contained in:
parent
fac6f54d75
commit
536271109b
@ -1,5 +1,6 @@
|
||||
package app.myzel394.alibi.services
|
||||
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.media.MediaRecorder
|
||||
import app.myzel394.alibi.dataStore
|
||||
import app.myzel394.alibi.db.AudioRecorderSettings
|
||||
@ -68,11 +69,35 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
|
||||
counter = files.size
|
||||
}
|
||||
|
||||
private fun fetchRecordingTime() {
|
||||
var oldAmount = 0L
|
||||
|
||||
for (file in outputFolder.listFiles() ?: emptyArray()) {
|
||||
if (file.nameWithoutExtension.toIntOrNull() == null) {
|
||||
continue
|
||||
}
|
||||
|
||||
// It's better to at least get an approximate value, than to crash
|
||||
runCatching {
|
||||
val amount = MediaMetadataRetriever().run {
|
||||
setDataSource(file.absolutePath)
|
||||
extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toIntOrNull()
|
||||
?: 0
|
||||
}
|
||||
|
||||
oldAmount += amount
|
||||
}
|
||||
}
|
||||
|
||||
recordingTime = oldAmount
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
super.start()
|
||||
|
||||
outputFolder.mkdirs()
|
||||
fetchCounterValue()
|
||||
fetchRecordingTime()
|
||||
|
||||
scope.launch {
|
||||
dataStore.data.collectLatest { preferenceSettings ->
|
||||
|
@ -34,7 +34,7 @@ abstract class RecorderService : Service() {
|
||||
var onStateChange: ((RecorderState) -> Unit)? = null
|
||||
|
||||
var recordingTime = 0L
|
||||
private set
|
||||
protected set
|
||||
private lateinit var recordingTimeTimer: ScheduledExecutorService
|
||||
var onRecordingTimeChange: ((Long) -> Unit)? = null
|
||||
var notificationDetails: RecorderNotificationHelper.NotificationDetails? = null
|
||||
|
Loading…
x
Reference in New Issue
Block a user