[Android] Disable the volume gesture/boost on devices with fixed volume

Nicolas Pomepuy git at videolan.org
Mon Oct 7 09:28:52 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Sep 30 08:52:45 2024 +0200| [d7f9e28e9887f59174824787f766b89c866c4e8a] | committer: Nicolas Pomepuy

Disable the volume gesture/boost on devices with fixed volume

Fixes #3088

> https://code.videolan.org/videolan/vlc-android/commit/d7f9e28e9887f59174824787f766b89c866c4e8a
---

 application/resources/src/main/res/values/strings.xml  |  1 +
 .../vlc/gui/preferences/PreferencesVideoControls.kt    | 18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 257d2127c3..8a4fdf618b 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -169,6 +169,7 @@
     <string name="track_codec_info">Codec: %1$s\n</string>
     <string name="track_language_info">Language: %1$s\n</string>
     <string name="volume">Volume</string>
+    <string name="system_volume_disabled">%s\nNo access to system volume</string>
     <string name="sound_on">Sound On</string>
     <string name="sound_off">Sound Off</string>
     <string name="brightness">Brightness</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
index 5bf029dcea..97dc533919 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideoControls.kt
@@ -23,7 +23,10 @@
 package org.videolan.vlc.gui.preferences
 
 import android.content.SharedPreferences
+import android.media.AudioManager
 import android.os.Bundle
+import androidx.core.content.getSystemService
+import androidx.preference.CheckBoxPreference
 import androidx.preference.Preference
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.resources.AndroidDevices
@@ -55,8 +58,10 @@ class PreferencesVideoControls : BasePreferenceFragment(), SharedPreferences.OnS
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        val audioBoostPref = findPreference<CheckBoxPreference>(AUDIO_BOOST)
+        val volumeGesturePref = findPreference<CheckBoxPreference>(ENABLE_VOLUME_GESTURE)
         findPreference<Preference>(POPUP_KEEPSCREEN)?.isVisible = !AndroidUtil.isOOrLater
-        findPreference<Preference>(AUDIO_BOOST)?.isVisible = !AndroidDevices.isAndroidTv
+        audioBoostPref?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(ENABLE_DOUBLE_TAP_SEEK)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(ENABLE_DOUBLE_TAP_PLAY)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(ENABLE_SCALE_GESTURE)?.isVisible = !AndroidDevices.isAndroidTv
@@ -64,11 +69,20 @@ class PreferencesVideoControls : BasePreferenceFragment(), SharedPreferences.OnS
         findPreference<Preference>(ENABLE_FASTPLAY)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(FASTPLAY_SPEED)?.isVisible = !AndroidDevices.isAndroidTv
         findPreference<Preference>(SCREENSHOT_MODE)?.isVisible = !AndroidDevices.isAndroidTv
-        findPreference<Preference>(ENABLE_VOLUME_GESTURE)?.isVisible = AndroidDevices.hasTsp
+        volumeGesturePref?.isVisible = AndroidDevices.hasTsp
         findPreference<Preference>(ENABLE_BRIGHTNESS_GESTURE)?.isVisible = AndroidDevices.hasTsp
         findPreference<Preference>(POPUP_KEEPSCREEN)?.isVisible = !AndroidDevices.isAndroidTv && !AndroidUtil.isOOrLater
         findPreference<Preference>(KEY_VIDEO_DOUBLE_TAP_JUMP_DELAY)?.title = getString(if (AndroidDevices.isAndroidTv) R.string.video_key_jump_delay else R.string.video_double_tap_jump_delay)
         updateHudTimeoutSummary()
+        val audiomanager = requireActivity().getSystemService<AudioManager>()!!
+        if (audiomanager.isVolumeFixed) {
+            audioBoostPref?.isChecked = false
+            audioBoostPref?.isEnabled = false
+            audioBoostPref?.summary = getString(R.string.system_volume_disabled, audioBoostPref?.summary)
+            volumeGesturePref?.isChecked = false
+            volumeGesturePref?.isEnabled = false
+            volumeGesturePref?.summary = getString(R.string.system_volume_disabled, volumeGesturePref?.summary)
+        }
 
     }
 



More information about the Android mailing list