[Android] catch libvlc options IllegalStateException
Mehdi Sabwat
git at videolan.org
Mon Mar 23 18:29:59 CET 2020
vlc-android | branch: master | Mehdi Sabwat <mehdisabwat at gmail.com> | Tue Mar 10 14:47:53 2020 +0100| [0e476d20655ec21f730784b8e1b51bfb4026cca4] | committer: Geoffrey Métais
catch libvlc options IllegalStateException
> https://code.videolan.org/videolan/vlc-android/commit/0e476d20655ec21f730784b8e1b51bfb4026cca4
---
application/resources/src/main/res/values/strings.xml | 1 +
.../television/ui/preferences/PreferencesAdvanced.kt | 17 ++++++++++++++---
.../vlc/gui/preferences/PreferencesAdvanced.kt | 18 ++++++++++++++----
3 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index de90c241b..a0e1b030c 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -481,6 +481,7 @@
<string name="dump_logcat_success">Logcat successfully dumped to %1$s!</string>
<string name="dump_logcat_failure">Failed to dump logcat.</string>
<string name="custom_libvlc_options">Custom libVLC options</string>
+ <string name="custom_libvlc_options_invalid">Invalid libVLC options!</string>
<string name="serious_crash">Unfortunately, a serious error has occurred and VLC had to close.</string>
<string name="help_us_send_log">Help us improving VLC by sending the following crash log:</string>
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 db558a15d..7068aa2aa 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
@@ -39,6 +39,7 @@ import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.AndroidDevices
import org.videolan.resources.VLCInstance
+import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.gui.DebugLogActivity
@@ -114,7 +115,7 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
}
"dump_media_db" -> {
if (Medialibrary.getInstance().isWorking)
- UiTools.snacker(view!!, getString(R.string.settings_ml_block_scan))
+ activity?.let { Toast.makeText(it, R.string.settings_ml_block_scan, Toast.LENGTH_LONG).show() }
else {
val dst = File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + Medialibrary.VLC_MEDIA_DB_NAME)
launch {
@@ -144,15 +145,25 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
editor.putInt("network_caching_value", 0)
val networkCachingPref = findPreference<EditTextPreference>(key)
networkCachingPref?.text = ""
- Toast.makeText(activity, R.string.network_caching_popup, Toast.LENGTH_SHORT).show()
+ activity?.let { Toast.makeText(it, R.string.network_caching_popup, Toast.LENGTH_SHORT).show() }
}
editor.apply()
VLCInstance.restart()
(activity as? PreferencesActivity)?.restartMediaPlayer()
}
+ "custom_libvlc_options" -> {
+ try {
+ VLCInstance.restart()
+ } catch (e: IllegalStateException){
+ activity?.let { Toast.makeText(it, R.string.custom_libvlc_options_invalid, Toast.LENGTH_LONG).show() }
+ sharedPreferences.putSingle("custom_libvlc_options", "")
+ } finally {
+ (activity as? PreferencesActivity)?.restartMediaPlayer()
+ }
+ }
// No break because need VLCInstance.restart();
- "opengl", "chroma_format", "custom_libvlc_options", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode" -> {
+ "opengl", "chroma_format", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode" -> {
VLCInstance.restart()
(activity as? PreferencesActivity)?.restartMediaPlayer()
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index 9ea25b1f7..94c2a8d9a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -37,6 +37,7 @@ import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.AndroidDevices
import org.videolan.resources.VLCInstance
+import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.gui.DebugLogActivity
@@ -141,14 +142,23 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
networkCachingPref?.text = ""
UiTools.snacker(view!!, R.string.network_caching_popup)
}
-
editor.apply()
VLCInstance.restart()
- if (activity != null)
- (activity as PreferencesActivity).restartMediaPlayer()
+ (activity as? PreferencesActivity)?.restartMediaPlayer()
}
// No break because need VLCInstance.restart();
- "opengl", "chroma_format", "custom_libvlc_options", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode" -> {
+ "custom_libvlc_options" -> {
+ try {
+ VLCInstance.restart()
+ } catch (e: IllegalStateException){
+ view?.let { UiTools.snacker(it, R.string.custom_libvlc_options_invalid) }
+ sharedPreferences.putSingle("custom_libvlc_options", "")
+ } finally {
+ (activity as? PreferencesActivity)?.restartMediaPlayer()
+ }
+
+ }
+ "opengl", "chroma_format", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode" -> {
VLCInstance.restart()
(activity as? PreferencesActivity)?.restartMediaPlayer()
}
More information about the Android
mailing list