fix: Release MediaActionSound
after playing (#2390)
* fix: Release `MediaActionSound` after playing * Make it a bit more expressive
This commit is contained in:
parent
e825e21e1d
commit
bdad4e1acb
@ -14,6 +14,9 @@ import kotlin.coroutines.suspendCoroutine
|
|||||||
|
|
||||||
suspend fun CameraCaptureSession.capture(captureRequest: CaptureRequest, enableShutterSound: Boolean): TotalCaptureResult =
|
suspend fun CameraCaptureSession.capture(captureRequest: CaptureRequest, enableShutterSound: Boolean): TotalCaptureResult =
|
||||||
suspendCoroutine { continuation ->
|
suspendCoroutine { continuation ->
|
||||||
|
val shutterSound = if (enableShutterSound) MediaActionSound() else null
|
||||||
|
shutterSound?.load(MediaActionSound.SHUTTER_CLICK)
|
||||||
|
|
||||||
this.capture(
|
this.capture(
|
||||||
captureRequest,
|
captureRequest,
|
||||||
object : CameraCaptureSession.CaptureCallback() {
|
object : CameraCaptureSession.CaptureCallback() {
|
||||||
@ -21,14 +24,14 @@ suspend fun CameraCaptureSession.capture(captureRequest: CaptureRequest, enableS
|
|||||||
super.onCaptureCompleted(session, request, result)
|
super.onCaptureCompleted(session, request, result)
|
||||||
|
|
||||||
continuation.resume(result)
|
continuation.resume(result)
|
||||||
|
shutterSound?.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCaptureStarted(session: CameraCaptureSession, request: CaptureRequest, timestamp: Long, frameNumber: Long) {
|
override fun onCaptureStarted(session: CameraCaptureSession, request: CaptureRequest, timestamp: Long, frameNumber: Long) {
|
||||||
super.onCaptureStarted(session, request, timestamp, frameNumber)
|
super.onCaptureStarted(session, request, timestamp, frameNumber)
|
||||||
|
|
||||||
if (enableShutterSound) {
|
if (enableShutterSound) {
|
||||||
val mediaActionSound = MediaActionSound()
|
shutterSound?.play(MediaActionSound.SHUTTER_CLICK)
|
||||||
mediaActionSound.play(MediaActionSound.SHUTTER_CLICK)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user