Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added option to consider ringer mode in Android #2811

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class CameraSession(private val context: Context, private val callback: Callback
}
}

suspend fun takePhoto(flash: Flash, enableShutterSound: Boolean, outputOrientation: Orientation): Photo {
suspend fun takePhoto(flash: Flash, enableShutterSound: Boolean, isAppliedRingerMode: Boolean, outputOrientation: Orientation): Photo {
val camera = camera ?: throw CameraNotReadyError()
val photoOutput = photoOutput ?: throw PhotoNotEnabledError()

Expand All @@ -502,7 +502,7 @@ class CameraSession(private val context: Context, private val callback: Callback

photoOutput.flashMode = flash.toFlashMode()
photoOutput.targetRotation = outputOrientation.toSurfaceRotation()
val enableShutterSoundActual = getEnableShutterSoundActual(enableShutterSound)
val enableShutterSoundActual = getEnableShutterSoundActual(enableShutterSound, isAppliedRingerMode)

val photoFile = photoOutput.takePicture(context, enableShutterSoundActual, metadataProvider, callback, CameraQueues.cameraExecutor)
val isMirrored = photoFile.metadata.isReversedHorizontal
Expand All @@ -517,10 +517,12 @@ class CameraSession(private val context: Context, private val callback: Callback
return Photo(photoFile.uri.path, width, height, outputOrientation, isMirrored)
}

private fun getEnableShutterSoundActual(enable: Boolean): Boolean {
if (enable && audioManager.ringerMode != AudioManager.RINGER_MODE_NORMAL) {
Log.i(TAG, "Ringer mode is silent (${audioManager.ringerMode}), disabling shutter sound...")
return false
private fun getEnableShutterSoundActual(enable: Boolean, isAppliedRingerMode: Boolean): Boolean {
if (isAppliedRingerMode) {
if (enable && audioManager.ringerMode != AudioManager.RINGER_MODE_NORMAL) {
Log.i(TAG, "Ringer mode is silent (${audioManager.ringerMode}), disabling shutter sound...")
return false
}
}

return enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ suspend fun CameraView.takePhoto(optionsMap: ReadableMap): WritableMap {

val flash = options["flash"] as? String ?: "off"
val enableShutterSound = options["enableShutterSound"] as? Boolean ?: true
val isAppliedRingerMode = options["isAppliedRingerMode"] as? Boolean ?: false

val photo = cameraSession.takePhoto(
Flash.fromUnionValue(flash),
enableShutterSound,
isAppliedRingerMode,
orientation
)

Expand Down
9 changes: 9 additions & 0 deletions package/src/types/PhotoFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export interface TakePhotoOptions {
* @default true
*/
enableShutterSound?: boolean
/**
* (android)
* If this option is set to true,
* When ringerMode is RINGER_MODE_NORMAL, the shutterSound option is applied.
* When the ringer mode is RINGER_MODE_SILENT or RINGER MODE VIBRATE, the shutter Sound option is ignored.
*
* @default false
*/
isAppliedRingerMode?: boolean
}

/**
Expand Down