[Android] Coerce the slider value to avoid crashing

Nicolas Pomepuy git at videolan.org
Wed Jun 19 16:29:13 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Jun 19 09:12:37 2024 +0200| [e00f8e1f0c24db1e6e0d0b2f85c504924258ab25] | committer: Duncan McNamara

Coerce the slider value to avoid crashing

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

 .../src/org/videolan/vlc/gui/audio/EqualizerFragment.kt | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
index 434d439268..f590ae1e62 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
@@ -27,10 +27,19 @@ import android.os.Bundle
 import android.text.Editable
 import android.text.TextWatcher
 import android.util.Log
-import android.view.*
+import android.view.KeyEvent
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
 import android.view.ViewGroup.LayoutParams
-import android.widget.*
+import android.view.WindowManager
+import android.widget.AdapterView
 import android.widget.AdapterView.OnItemSelectedListener
+import android.widget.ArrayAdapter
+import android.widget.EditText
+import android.widget.FrameLayout
+import android.widget.LinearLayout
+import android.widget.Toast
 import androidx.appcompat.app.AlertDialog
 import androidx.databinding.DataBindingUtil
 import androidx.databinding.ObservableBoolean
@@ -250,8 +259,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment(), Slider.OnChangeListene
                     if (i == index) {
                         continue
                     }
-
-                    eqBandsViews[i].setProgress(oldBands[i] + delta / (abs(i - index) * abs(i - index) * abs(i - index) + 1))
+                    eqBandsViews[i].setProgress((oldBands[i] + delta / (abs(i - index) * abs(i - index) * abs(i - index) + 1)).coerceIn(0, EqualizerBar.RANGE * 2))
 
                     if (binding.equalizerButton.isChecked) {
 
@@ -263,7 +271,6 @@ class EqualizerFragment : VLCBottomSheetDialogFragment(), Slider.OnChangeListene
 
             if (binding.equalizerButton.isChecked) PlaybackService.equalizer.value = equalizer
 
-
         }
 
         override fun onStartTrackingTouch() {



More information about the Android mailing list