[Android] Fix a crash after the subtitle color migration failed
Nicolas Pomepuy
git at videolan.org
Mon Mar 17 06:05:53 UTC 2025
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Mar 14 09:15:20 2025 +0100| [8a4a48eacc88e31b3c766a431225c3f4185f0f21] | committer: Nicolas Pomepuy
Fix a crash after the subtitle color migration failed
> https://code.videolan.org/videolan/vlc-android/commit/8a4a48eacc88e31b3c766a431225c3f4185f0f21
---
.../main/java/org/videolan/resources/VLCOptions.kt | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/VLCOptions.kt b/application/resources/src/main/java/org/videolan/resources/VLCOptions.kt
index b510cabda4..f42dd7ab19 100644
--- a/application/resources/src/main/java/org/videolan/resources/VLCOptions.kt
+++ b/application/resources/src/main/java/org/videolan/resources/VLCOptions.kt
@@ -22,6 +22,7 @@ package org.videolan.resources
import android.content.Context
import android.content.SharedPreferences
+import android.graphics.Color
import android.media.AudioManager
import android.os.Build
import android.util.Log
@@ -40,7 +41,7 @@ import org.videolan.tools.putSingle
import org.videolan.vlc.VlcMigrationHelper
import org.videolan.vlc.isVLC4
import java.io.File
-import java.util.*
+import java.util.Collections
object VLCOptions {
private const val TAG = "VLC/VLCConfig"
@@ -87,7 +88,25 @@ object VLCOptions {
val freetypeRelFontsize = pref.getString("subtitles_size", "16")
val freetypeBold = pref.getBoolean("subtitles_bold", false)
- val freetypeColor = Integer.decode(String.format("0x%06X", (0xFFFFFF and pref.getInt("subtitles_color", 16777215))))
+ val freetypeColor = try {
+ Integer.decode(String.format("0x%06X", (0xFFFFFF and pref.getInt("subtitles_color", 16777215))))
+ } catch (e: ClassCastException) {
+ Log.w(TAG, "Forced migration of subtitles color")
+ //Migration failed somehow. Migrating here
+ var color = 16777215
+ pref.getString("subtitles_color", "16777215")?.let {oldSetting ->
+ try {
+ val oldColor = oldSetting.toInt()
+ val newColor = Color.argb(255, Color.red(oldColor), Color.green(oldColor), Color.blue(oldColor))
+ pref.putSingle("subtitles_color", newColor)
+ color = newColor
+ } catch (e: Exception) {
+ pref.edit().remove("subtitles_color").apply()
+ }
+ }
+
+ color
+ }
val freetypeColorOpacity = pref.getInt("subtitles_color_opacity", 255)
val freetypeBackgroundColor = Integer.decode(String.format("0x%06X", (0xFFFFFF and pref.getInt("subtitles_background_color", 16777215))))
More information about the Android
mailing list