feat: Add VideoRecorderService

This commit is contained in:
Myzel394 2023-08-12 21:30:29 +02:00
parent 8bd9e3d35a
commit 0ef93e2b47
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
4 changed files with 72 additions and 3 deletions

View File

@ -4,9 +4,15 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-feature android:name="android.hardware.camera.any" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.microphone" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<application
android:name=".UpdateSettingsApp"
android:allowBackup="true"

View File

@ -12,9 +12,6 @@ class AudioRecorderService: IntervalRecorderService() {
private set
var onError: () -> Unit = {}
val filePath: String
get() = "$folder/$counter.${settings!!.fileExtension}"
private fun createRecorder(): MediaRecorder {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
MediaRecorder(this)

View File

@ -30,6 +30,9 @@ abstract class IntervalRecorderService: ExtraRecorderInformationService() {
var settings: Settings? = null
protected set
val filePath: String
get() = "$folder/$counter.${settings!!.fileExtension}"
private lateinit var cycleTimer: ScheduledExecutorService
fun createLastRecording(): LastRecording = LastRecording(

View File

@ -0,0 +1,63 @@
package app.myzel394.alibi.services
import androidx.camera.view.CameraController.VIDEO_CAPTURE
import androidx.camera.view.LifecycleCameraController
import androidx.camera.view.video.ExperimentalVideo
import androidx.camera.view.video.OnVideoSavedCallback
import androidx.camera.view.video.OutputFileOptions
import androidx.camera.view.video.OutputFileResults
import androidx.core.content.ContextCompat
import androidx.lifecycle.LifecycleOwner
import java.io.File
@ExperimentalVideo class VideoRecorderService: IntervalRecorderService() {
var amplitudesAmount = 1000
val cameraController = LifecycleCameraController(this)
var onError: () -> Unit = {}
public fun bindToLifecycle(lifecycleOwner: LifecycleOwner) {
cameraController.bindToLifecycle(lifecycleOwner)
}
public fun unbindLifecycle() {
cameraController.unbind()
}
private fun refreshController() {
if (cameraController.isRecording) {
cameraController.stopRecording()
}
cameraController.startRecording(
OutputFileOptions
.builder(File(filePath))
.build(),
ContextCompat.getMainExecutor(this),
object: OnVideoSavedCallback {
override fun onVideoSaved(outputFileResults: OutputFileResults) {
}
override fun onError(videoCaptureError: Int, message: String, cause: Throwable?) {
onError()
}
}
)
}
override fun start() {
cameraController.setEnabledUseCases(VIDEO_CAPTURE)
super.start()
}
override fun startNewCycle() {
super.startNewCycle()
refreshController()
}
override fun getAmplitudeAmount(): Int = amplitudesAmount
override fun getAmplitude(): Int = 0
}