From 168bb226705d3da197b48cf5d592df230fc25626 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 3 Jan 2025 11:17:57 +0800 Subject: [PATCH] feat: custom subtitle bg stroke Closes #90 Signed-off-by: bggRGjQaUbCoE --- .../video/detail/introduction/controller.dart | 3 +- .../video/detail/widgets/header_control.dart | 39 ++++++++++++++++++- lib/plugin/pl_player/controller.dart | 13 ++++++- lib/utils/storage.dart | 4 ++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 28e5a869..601cb500 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -148,7 +148,8 @@ class VideoIntroController extends GetxController Get.find(tag: heroTag); if (videoDetailController.videoItem['pic'] == null || videoDetailController.videoItem['pic'] == '' || - videoDetailController.videoUrl.isNullOrEmpty) { + (videoDetailController.videoUrl.isNullOrEmpty && + videoDetailController.isQuerying.not)) { videoDetailController.videoItem['pic'] = result['data'].pic; } } catch (_) {} diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index 02d9f418..20dfb6da 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -292,7 +292,7 @@ class _HeaderControlState extends State { onTap: () => {Get.back(), showSetDanmaku()}, leading: const Icon(Icons.subtitles_outlined, size: 20), - title: const Text('弹幕设置', style: titleStyle), + title: const Text('弹幕/字幕设置', style: titleStyle), ), ListTile( dense: true, @@ -1025,6 +1025,7 @@ class _HeaderControlState extends State { int subtitlePaddingH = widget.controller.subtitlePaddingH; int subtitlePaddingB = widget.controller.subtitlePaddingB; double subtitleBgOpaticy = widget.controller.subtitleBgOpaticy; + double subtitleBgStroke = widget.controller.subtitleBgStroke; final DanmakuController? danmakuController = widget.controller.danmakuController; @@ -1058,7 +1059,7 @@ class _HeaderControlState extends State { children: [ const SizedBox( height: 45, - child: Center(child: Text('弹幕设置', style: titleStyle)), + child: Center(child: Text('弹幕/字幕设置', style: titleStyle)), ), const SizedBox(height: 10), Row( @@ -1649,6 +1650,40 @@ class _HeaderControlState extends State { ), ), ), + Text('字幕背景边框粗细(背景不透明度为0时启用) $subtitleBgStroke'), + Padding( + padding: const EdgeInsets.only( + top: 0, + bottom: 6, + left: 10, + right: 10, + ), + child: SliderTheme( + data: SliderThemeData( + trackShape: MSliderTrackShape(), + thumbColor: Theme.of(context).colorScheme.primary, + activeTrackColor: Theme.of(context).colorScheme.primary, + trackHeight: 10, + thumbShape: const RoundSliderThumbShape( + enabledThumbRadius: 6.0), + ), + child: Slider( + min: 0, + max: 3, + divisions: 6, + value: subtitleBgStroke, + label: '$subtitleBgStroke', + onChanged: (double val) { + subtitleBgStroke = val; + widget.controller + ..subtitleBgStroke = subtitleBgStroke + ..updateSubtitleStyle() + ..putDanmakuSettings(); + setState(() {}); + }, + ), + ), + ), ], ), ), diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 4ffae7ab..8db22eb0 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -260,12 +260,18 @@ class PlPlayerController { late int subtitlePaddingH = GStorage.subtitlePaddingH; late int subtitlePaddingB = GStorage.subtitlePaddingB; late double subtitleBgOpaticy = GStorage.subtitleBgOpaticy; + late double subtitleBgStroke = GStorage.subtitleBgStroke; // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; final GlobalKey key = GlobalKey(); + Paint get subtitleBg => Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = subtitleBgStroke + ..color = Colors.black; + TextStyle get subTitleStyle => TextStyle( height: 1.5, fontSize: @@ -274,7 +280,11 @@ class PlPlayerController { wordSpacing: 0.1, color: Colors.white, fontWeight: FontWeight.normal, - backgroundColor: Colors.black.withOpacity(subtitleBgOpaticy), + background: + subtitleBgOpaticy == 0 && subtitleBgStroke != 0 ? subtitleBg : null, + backgroundColor: subtitleBgOpaticy == 0 + ? null + : Colors.black.withOpacity(subtitleBgOpaticy), ); SubtitleViewConfiguration get subtitleViewConfiguration => @@ -1340,6 +1350,7 @@ class PlPlayerController { setting.put(SettingBoxKey.subtitlePaddingH, subtitlePaddingH); setting.put(SettingBoxKey.subtitlePaddingB, subtitlePaddingB); setting.put(SettingBoxKey.subtitleBgOpaticy, subtitleBgOpaticy); + setting.put(SettingBoxKey.subtitleBgStroke, subtitleBgStroke); } Future dispose({String type = 'single'}) async { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index b2c3e4dd..7d07a579 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -160,6 +160,9 @@ class GStorage { static double get subtitleBgOpaticy => setting.get(SettingBoxKey.subtitleBgOpaticy, defaultValue: 0.67); + static double get subtitleBgStroke => + setting.get(SettingBoxKey.subtitleBgStroke, defaultValue: 0.0); + static bool get badCertificateCallback => setting.get(SettingBoxKey.badCertificateCallback, defaultValue: false); @@ -369,6 +372,7 @@ class SettingBoxKey { subtitlePaddingH = 'subtitlePaddingH', subtitlePaddingB = 'subtitlePaddingB', subtitleBgOpaticy = 'subtitleBgOpaticy', + subtitleBgStroke = 'subtitleBgStroke', badCertificateCallback = 'badCertificateCallback', // Sponsor Block