mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
fix video capture sound playing in video recording
- add custom MediaActionSound, with functionality to notify callers when playing sound ends - only start video recording when the sound has played completely
This commit is contained in:
@ -57,7 +57,7 @@ class CameraXPreview(
|
||||
private val contentResolver = activity.contentResolver
|
||||
private val mainExecutor = ContextCompat.getMainExecutor(activity)
|
||||
private val displayManager = activity.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
||||
private val mediaSoundHelper = MediaSoundHelper()
|
||||
private val mediaSoundHelper = MediaSoundHelper(activity)
|
||||
private val windowMetricsCalculator = WindowMetricsCalculator.getOrCreate()
|
||||
private val videoQualityManager = VideoQualityManager(activity)
|
||||
private val imageQualityManager = ImageQualityManager(activity)
|
||||
@ -353,6 +353,11 @@ class CameraXPreview(
|
||||
orientationEventListener.disable()
|
||||
}
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
super.onDestroy(owner)
|
||||
mediaSoundHelper.release()
|
||||
}
|
||||
|
||||
override fun isInPhotoMode(): Boolean {
|
||||
return isPhotoCapture
|
||||
}
|
||||
@ -540,7 +545,14 @@ class CameraXPreview(
|
||||
|
||||
override fun toggleRecording() {
|
||||
if (currentRecording == null || recordingState is VideoRecordEvent.Finalize) {
|
||||
startRecording()
|
||||
if (config.isSoundEnabled) {
|
||||
mediaSoundHelper.playStartVideoRecordingSound(onPlayComplete = {
|
||||
startRecording()
|
||||
})
|
||||
listener.onVideoRecordingStarted()
|
||||
} else {
|
||||
startRecording()
|
||||
}
|
||||
} else {
|
||||
currentRecording?.stop()
|
||||
currentRecording = null
|
||||
@ -571,7 +583,6 @@ class CameraXPreview(
|
||||
recordingState = recordEvent
|
||||
when (recordEvent) {
|
||||
is VideoRecordEvent.Start -> {
|
||||
playStartVideoRecordingSoundIfEnabled()
|
||||
listener.onVideoRecordingStarted()
|
||||
}
|
||||
|
||||
@ -598,12 +609,6 @@ class CameraXPreview(
|
||||
}
|
||||
}
|
||||
|
||||
private fun playStartVideoRecordingSoundIfEnabled() {
|
||||
if (config.isSoundEnabled) {
|
||||
mediaSoundHelper.playStartVideoRecordingSound()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playStopVideoRecordingSoundIfEnabled() {
|
||||
if (config.isSoundEnabled) {
|
||||
mediaSoundHelper.playStopVideoRecordingSound()
|
||||
|
Reference in New Issue
Block a user