android: Add a PiP interface to mute / unmute

This commit is contained in:
Abandoned Cart 2023-06-16 18:50:36 -04:00
parent eea2145698
commit e31152ee34
4 changed files with 68 additions and 0 deletions

View File

@ -63,6 +63,10 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
private val actionPause = "ACTION_EMULATOR_PAUSE" private val actionPause = "ACTION_EMULATOR_PAUSE"
private val actionPlay = "ACTION_EMULATOR_PLAY" 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() private val settingsViewModel: SettingsViewModel by viewModels()
@ -305,6 +309,38 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
pictureInPictureActions.add(pauseRemoteAction) 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) } return this.apply { setActions(pictureInPictureActions) }
} }
@ -326,6 +362,18 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
} else if (intent.action == actionPause) { } else if (intent.action == actionPause) {
if (!NativeLibrary.isPaused()) NativeLibrary.pauseEmulation() 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() buildPictureInPictureParams()
} }
} }

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,9v6h4l5,5V4l-5,5H7z" />
</vector>

View File

@ -387,6 +387,8 @@
<string name="picture_in_picture_description">Minimize window when placed in the background</string> <string name="picture_in_picture_description">Minimize window when placed in the background</string>
<string name="pause">Pause</string> <string name="pause">Pause</string>
<string name="play">Play</string> <string name="play">Play</string>
<string name="mute">Mute</string>
<string name="audio">Audio</string>
<!-- Licenses screen strings --> <!-- Licenses screen strings -->
<string name="licenses">Licenses</string> <string name="licenses">Licenses</string>