From cae5befa634a085b00c9f335996b92a97779f7e3 Mon Sep 17 00:00:00 2001 From: Starfallen <36763490+Starfallan@users.noreply.github.com> Date: Sat, 11 Jul 2026 08:15:08 +0800 Subject: [PATCH] fix(player): preserve default codec preferences after upgrade (#2444) * fix(player): preserve default codec preferences after upgrade * update --------- Co-authored-by: dom --- lib/pages/setting/models/video_settings.dart | 18 +++++++----------- lib/utils/storage_pref.dart | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/pages/setting/models/video_settings.dart b/lib/pages/setting/models/video_settings.dart index 2136518ea..1888ffabc 100644 --- a/lib/pages/setting/models/video_settings.dart +++ b/lib/pages/setting/models/video_settings.dart @@ -127,10 +127,8 @@ List get videoSettings => [ NormalModel( title: '首选解码格式', leading: const Icon(Icons.movie_creation_outlined), - getSubtitle: () { - final list = Pref.preferCodecs; - return '首选解码格式:${(list.isEmpty ? '第一个可用' : list.map((i) => i.name).join(","))},请根据设备支持情况与需求调整'; - }, + getSubtitle: () => + '首选解码格式:${(Pref.preferCodecs.map((i) => i.name).join(","))},请根据设备支持情况与需求调整', onTap: _showCodecsDialog, ), if (kDebugMode || Platform.isAndroid) @@ -356,13 +354,11 @@ Future _showCodecsDialog( values: {for (final e in VideoDecodeFormatType.values) e: e.name}, ), ); - if (res != null) { - await (res.isEmpty - ? GStorage.setting.delete(SettingBoxKey.preferCodecs) - : GStorage.setting.put( - SettingBoxKey.preferCodecs, - res.map((i) => i.name).toList(), - )); + if (res != null && res.isNotEmpty) { + await GStorage.setting.put( + SettingBoxKey.preferCodecs, + res.map((i) => i.name).toList(), + ); setState(); } } diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 14cdff96a..e6a0ddae7 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -267,10 +267,10 @@ abstract final class Pref { } final codecs = _setting.get(SettingBoxKey.preferCodecs); - if (codecs is List && codecs.isNotEmpty) { + if (codecs is List) { return codecs.map((i) => VideoDecodeFormatType.values.byName(i)).toList(); } - return const []; + return const [.AVC, .AV1]; } static String get hardwareDecoding => _setting.get(