[Android] Fix soundfont picker not working on TV

Nicolas Pomepuy git at videolan.org
Wed Aug 7 13:41:51 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Aug  1 14:48:51 2024 +0200| [f20c417b644bb814f5b797a4aeeff1e5dcbc8838] | committer: Duncan McNamara

Fix soundfont picker not working on TV

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

 .../ui/preferences/BasePreferenceFragment.kt       | 12 ++++++
 .../ui/preferences/PreferencesAdvanced.kt          |  6 ---
 .../television/ui/preferences/PreferencesAudio.kt  | 43 +++++++++++++++++++++-
 3 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/BasePreferenceFragment.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/BasePreferenceFragment.kt
index f70fa49bc3..f8e60fefaa 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/BasePreferenceFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/BasePreferenceFragment.kt
@@ -24,14 +24,17 @@
 package org.videolan.television.ui.preferences
 
 import android.app.Fragment
+import android.content.Intent
 import android.os.Bundle
 import androidx.leanback.preference.LeanbackPreferenceFragment
 import androidx.preference.EditTextPreference
 import androidx.preference.Preference
 import androidx.preference.PreferenceDialogFragment
+import org.videolan.television.ui.dialogs.ConfirmationTvActivity
 
 import org.videolan.vlc.R
 
+const val RESTART_CODE = 10001
 abstract class BasePreferenceFragment : LeanbackPreferenceFragment() {
 
     protected abstract fun getXml(): Int
@@ -56,6 +59,15 @@ abstract class BasePreferenceFragment : LeanbackPreferenceFragment() {
         } else null
     }
 
+    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+        super.onActivityResult(requestCode, resultCode, data)
+        if (requestCode == RESTART_CODE) {
+            if (resultCode == ConfirmationTvActivity.ACTION_ID_POSITIVE) {
+                android.os.Process.killProcess(android.os.Process.myPid())
+            }
+        }
+    }
+
     companion object {
         private const val DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG"
     }
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
index ca5766b028..dbdc910cc3 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
@@ -93,7 +93,6 @@ import java.io.File
 import java.io.IOException
 
 private const val FILE_PICKER_RESULT_CODE = 10000
-private const val RESTART_CODE = 10001
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener, CoroutineScope by MainScope() {
     override fun getXml(): Int {
@@ -309,11 +308,6 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
 
     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
         super.onActivityResult(requestCode, resultCode, data)
-        if (requestCode == RESTART_CODE) {
-            if (resultCode == ConfirmationTvActivity.ACTION_ID_POSITIVE) {
-                android.os.Process.killProcess(android.os.Process.myPid())
-            }
-        }
         if (data == null) return
         if (requestCode == FILE_PICKER_RESULT_CODE) {
             if (data.hasExtra(EXTRA_MRL)) {
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt
index 137e132745..cf59a61d60 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAudio.kt
@@ -23,7 +23,9 @@
 package org.videolan.television.ui.preferences
 
 import android.annotation.TargetApi
+import android.content.Intent
 import android.content.SharedPreferences
+import android.net.Uri
 import android.os.Build
 import android.os.Bundle
 import android.text.InputFilter
@@ -49,14 +51,21 @@ import org.videolan.tools.Settings
 import org.videolan.tools.putSingle
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
+import org.videolan.vlc.gui.browser.EXTRA_MRL
+import org.videolan.vlc.gui.browser.FilePickerActivity
+import org.videolan.vlc.gui.browser.KEY_PICKER_TYPE
+import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.restartMediaPlayer
 import org.videolan.vlc.isVLC4
+import org.videolan.vlc.media.MediaUtils
+import org.videolan.vlc.providers.PickerType
 import org.videolan.vlc.util.LocaleUtil
 import java.text.DecimalFormat
 import java.text.DecimalFormatSymbols
-import java.util.*
+import java.util.Locale
 
 private const val TAG = "VLC/PreferencesAudio"
+private const val FILE_PICKER_RESULT_CODE = 10000
 
 @Suppress("DEPRECATION")
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -169,6 +178,38 @@ class PreferencesAudio : BasePreferenceFragment(), SharedPreferences.OnSharedPre
         }
     }
 
+    override fun onPreferenceTreeClick(preference: Preference): Boolean {
+        if (preference.key == null) return false
+        when (preference.key) {
+            "soundfont" -> {
+                val filePickerIntent = Intent(activity, FilePickerActivity::class.java)
+                filePickerIntent.putExtra(KEY_PICKER_TYPE, PickerType.SOUNDFONT.ordinal)
+                startActivityForResult(
+                    filePickerIntent,
+                    FILE_PICKER_RESULT_CODE
+                )
+            }
+        }
+
+        return super.onPreferenceTreeClick(preference)
+    }
+
+    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+        super.onActivityResult(requestCode, resultCode, data)
+            if (data == null) return
+            if (requestCode == FILE_PICKER_RESULT_CODE) {
+                if (data.hasExtra(EXTRA_MRL)) {
+                    launch {
+                        MediaUtils.useAsSoundFont(activity, Uri.parse(data.getStringExtra(
+                            EXTRA_MRL
+                        )))
+                        VLCInstance.restart()
+                    }
+                    UiTools.restartDialog(activity!!, true, RESTART_CODE, this)
+                }
+        }
+    }
+
     private suspend fun restartLibVLC() {
         VLCInstance.restart()
         restartMediaPlayer()



More information about the Android mailing list