From e31152ee347c2dddeba847ca08bd101ef53d1cce Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Fri, 16 Jun 2023 18:50:36 -0400 Subject: [PATCH] android: Add a PiP interface to mute / unmute --- .../yuzu_emu/activities/EmulationActivity.kt | 48 +++++++++++++++++++ .../src/main/res/drawable/ic_pip_audio.xml | 9 ++++ .../app/src/main/res/drawable/ic_pip_mute.xml | 9 ++++ .../app/src/main/res/values/strings.xml | 2 + 4 files changed, 68 insertions(+) create mode 100644 src/android/app/src/main/res/drawable/ic_pip_audio.xml create mode 100644 src/android/app/src/main/res/drawable/ic_pip_mute.xml diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index f0a6753a9..8a071f4da 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt @@ -63,6 +63,10 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { private val actionPause = "ACTION_EMULATOR_PAUSE" private val actionPlay = "ACTION_EMULATOR_PLAY" + private val actionMute = "ACTION_EMULATOR_MUTE" + private val actionAudio = "ACTION_EMULATOR_AUDIO" + private var isAudioMuted = false + private var userAudio = IntSetting.AUDIO_VOLUME.int private val settingsViewModel: SettingsViewModel by viewModels() @@ -305,6 +309,38 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { pictureInPictureActions.add(pauseRemoteAction) } + if (isAudioMuted) { + val audioIcon = Icon.createWithResource(this@EmulationActivity, R.drawable.ic_pip_audio) + val audioPendingIntent = PendingIntent.getBroadcast( + this@EmulationActivity, + R.drawable.ic_pip_audio, + Intent(actionAudio), + pendingFlags + ) + val audioRemoteAction = RemoteAction( + audioIcon, + getString(R.string.audio), + getString(R.string.audio), + audioPendingIntent + ) + pictureInPictureActions.add(audioRemoteAction) + } else { + val muteIcon = Icon.createWithResource(this@EmulationActivity, R.drawable.ic_pip_mute) + val mutePendingIntent = PendingIntent.getBroadcast( + this@EmulationActivity, + R.drawable.ic_pip_mute, + Intent(actionMute), + pendingFlags + ) + val muteRemoteAction = RemoteAction( + muteIcon, + getString(R.string.mute), + getString(R.string.mute), + mutePendingIntent + ) + pictureInPictureActions.add(muteRemoteAction) + } + return this.apply { setActions(pictureInPictureActions) } } @@ -326,6 +362,18 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { } else if (intent.action == actionPause) { if (!NativeLibrary.isPaused()) NativeLibrary.pauseEmulation() } + if (intent.action == actionAudio) { + if (isAudioMuted) { + IntSetting.AUDIO_VOLUME.int = userAudio + isAudioMuted = false + } + } else if (intent.action == actionMute) { + if (!isAudioMuted) { + isAudioMuted = true + userAudio = IntSetting.AUDIO_VOLUME.int + IntSetting.AUDIO_VOLUME.int = 0 + } + } buildPictureInPictureParams() } } diff --git a/src/android/app/src/main/res/drawable/ic_pip_audio.xml b/src/android/app/src/main/res/drawable/ic_pip_audio.xml new file mode 100644 index 000000000..f7ed0862e --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_pip_audio.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_pip_mute.xml b/src/android/app/src/main/res/drawable/ic_pip_mute.xml new file mode 100644 index 000000000..a271c5fe8 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_pip_mute.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index cc1d8c39d..d4f089c7f 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -387,6 +387,8 @@ Minimize window when placed in the background Pause Play + Mute + Audio Licenses