From 0e476d20655ec21f730784b8e1b51bfb4026cca4 Mon Sep 17 00:00:00 2001 From: Mehdi Sabwat Date: Tue, 10 Mar 2020 14:47:53 +0100 Subject: [PATCH] catch libvlc options IllegalStateException --- .../resources/src/main/res/values/strings.xml | 1 + .../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 @@ Logcat successfully dumped to %1$s! Failed to dump logcat. Custom libVLC options + Invalid libVLC options! Unfortunately, a serious error has occurred and VLC had to close. Help us improving VLC by sending the following crash log: 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(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() }