Skip to content

Commit

Permalink
Mute Audio Default Setting (#268)
Browse files Browse the repository at this point in the history
* Implement default setting to start recordings muted or with audio

* use new .withAudioEnabled API

* Rename Mute Audio usages to default positive

* audio uistate

---------

Co-authored-by: Jaehwa Noh <shwoghk14@gmail.com>
  • Loading branch information
Kimblebee and Jaehwa-Noh authored Jan 21, 2025
1 parent e610e53 commit ebddf33
Show file tree
Hide file tree
Showing 26 changed files with 682 additions and 74 deletions.
318 changes: 318 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ private fun getPendingRecording(

context(CameraSessionContext)
private suspend fun startVideoRecordingInternal(
initialMuted: Boolean,
isInitialAudioEnabled: Boolean,
context: Context,
pendingRecord: PendingRecording,
maxDurationMillis: Long,
Expand All @@ -712,14 +712,15 @@ private suspend fun startVideoRecordingInternal(
// if the video recording isn't started with audio enabled, you will not be able to un-mute it
// the toggle should only affect whether or not the audio is muted.
// the permission will determine whether or not the audio is enabled.
val audioEnabled = checkSelfPermission(
val isAudioGranted = checkSelfPermission(
context,
Manifest.permission.RECORD_AUDIO
) == PackageManager.PERMISSION_GRANTED

pendingRecord.apply {
if (audioEnabled) {
withAudioEnabled()
if (isAudioGranted) {
Log.d(TAG, "INITIAL AUDIO $isInitialAudioEnabled")
withAudioEnabled(isInitialAudioEnabled)
}
}
.asPersistentRecording()
Expand Down Expand Up @@ -859,7 +860,7 @@ private suspend fun startVideoRecordingInternal(
}
}
}.apply {
mute(initialMuted)
mute(!isInitialAudioEnabled)
}
}

Expand Down Expand Up @@ -887,7 +888,7 @@ private suspend fun runVideoRecording(
onVideoRecord
)?.let {
startVideoRecordingInternal(
initialMuted = currentSettings.isAudioMuted,
isInitialAudioEnabled = currentSettings.isAudioEnabled,
context = context,
pendingRecord = it,
maxDurationMillis = maxDurationMillis,
Expand All @@ -898,8 +899,8 @@ private suspend fun runVideoRecording(

transientSettings.filterNotNull()
.collectLatest { newTransientSettings ->
if (currentSettings.isAudioMuted != newTransientSettings.isAudioMuted) {
recording.mute(newTransientSettings.isAudioMuted)
if (currentSettings.isAudioEnabled != newTransientSettings.isAudioEnabled) {
recording.mute(newTransientSettings.isAudioEnabled)
}
if (currentSettings.isFlashModeOn() !=
newTransientSettings.isFlashModeOn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal sealed interface PerpetualSessionSettings {
* The use cases typically will not need to be re-bound.
*/
internal data class TransientSessionSettings(
val isAudioMuted: Boolean,
val isAudioEnabled: Boolean,
val deviceRotation: DeviceRotation,
val flashMode: FlashMode,
val zoomScale: Float,
Expand Down
Loading

0 comments on commit ebddf33

Please # to comment.