feat: Improve settings for video recording

This commit is contained in:
Myzel394 2023-11-27 15:03:27 +01:00
parent b3bb43367a
commit 448108a974
No known key found for this signature in database
GPG Key ID: 50098FCA22080F0F
3 changed files with 30 additions and 9 deletions

View File

@ -6,7 +6,8 @@ import android.os.Build
import androidx.camera.video.Quality
import androidx.camera.video.QualitySelector
import app.myzel394.alibi.R
import app.myzel394.alibi.helpers.BatchesFolder
import app.myzel394.alibi.helpers.AudioBatchesFolder
import app.myzel394.alibi.helpers.VideoBatchesFolder
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.time.LocalDateTime
@ -75,9 +76,21 @@ data class RecordingInformation(
val maxDuration: Long,
val intervalDuration: Long,
val fileExtension: String,
val type: Type,
) {
fun hasRecordingsAvailable(context: Context): Boolean =
BatchesFolder.importFromFolder(folderPath, context).hasRecordingsAvailable()
when (type) {
Type.AUDIO -> AudioBatchesFolder.importFromFolder(folderPath, context)
.hasRecordingsAvailable()
Type.VIDEO -> VideoBatchesFolder.importFromFolder(folderPath, context)
.hasRecordingsAvailable()
}
enum class Type {
AUDIO,
VIDEO,
}
}
@Serializable

View File

@ -142,6 +142,7 @@ class AudioRecorderService :
maxDuration = settings.maxDuration,
fileExtension = settings.fileExtension,
intervalDuration = settings.intervalDuration,
type = RecordingInformation.Type.AUDIO,
)
override fun startNewCycle() {
@ -214,7 +215,7 @@ class AudioRecorderService :
super.onAudioDevicesAdded(addedDevices)
if (selectedMicrophone == null) {
return;
return
}
// We can't compare the ID, as it seems to be changing on each reconnect
@ -238,7 +239,7 @@ class AudioRecorderService :
super.onAudioDevicesRemoved(removedDevices)
if (selectedMicrophone == null) {
return;
return
}
if (removedDevices?.find { it.id == selectedMicrophone!!.deviceInfo.id } != null) {

View File

@ -58,7 +58,7 @@ class VideoRecorderService :
runInMain {
camera = cameraProvider!!.bindToLifecycle(
this,
settings.cameraSelector,
CameraSelector.DEFAULT_BACK_CAMERA,
videoCapture
)
@ -136,6 +136,7 @@ class VideoRecorderService :
maxDuration = settings.maxDuration,
fileExtension = settings.fileExtension,
intervalDuration = settings.intervalDuration,
type = RecordingInformation.Type.VIDEO,
)
data class Settings(
@ -143,7 +144,6 @@ class VideoRecorderService :
override val intervalDuration: Long,
val folder: String? = null,
val targetVideoBitRate: Int? = null,
val cameraSelector: CameraSelector = CameraSelector.DEFAULT_BACK_CAMERA,
val quality: QualitySelector = QualitySelector.from(Quality.HIGHEST),
) : IntervalRecorderService.Settings(
maxDuration = maxDuration,
@ -162,9 +162,16 @@ class VideoRecorderService :
}
companion object {
fun from() = Settings(
maxDuration = 60_000,
intervalDuration = 10_000,
fun from(appSettings: AppSettings) = Settings(
// TODO: Migrate audioSettings
maxDuration = appSettings.audioRecorderSettings.maxDuration,
intervalDuration = appSettings.audioRecorderSettings.intervalDuration,
folder = appSettings.audioRecorderSettings.saveFolder,
targetVideoBitRate = appSettings.videoRecorderSettings.targetedVideoBitRate,
quality = appSettings.videoRecorderSettings.getQualitySelector()
?: QualitySelector.from(
Quality.HIGHEST
),
)
}
}