Skip to content

Commit

Permalink
feat: 新增弹幕描边粗细设置,默认值降低
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 25, 2024
1 parent 8dded51 commit 5f299d9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/pages/danmaku/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
late double opacityVal;
late double fontSizeVal;
late double danmakuDurationVal;
late double strokeWidth;
int latestAddedPosition = -1;

@override
Expand Down Expand Up @@ -65,6 +66,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
showArea = playerController.showArea;
opacityVal = playerController.opacityVal;
fontSizeVal = playerController.fontSizeVal;
strokeWidth = playerController.strokeWidth;
danmakuDurationVal = playerController.danmakuDurationVal;
}

Expand Down Expand Up @@ -136,6 +138,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
hideBottom: blockTypes.contains(4),
duration:
danmakuDurationVal / playerController.playbackSpeed,
strokeWidth: strokeWidth,
// initDuration /
// (danmakuSpeedVal * widget.playerController.playbackSpeed),
),
Expand Down
41 changes: 41 additions & 0 deletions lib/pages/video/detail/widgets/header_control.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math';

import 'package:floating/floating.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -724,6 +725,8 @@ class _HeaderControlState extends State<HeaderControl> {
double fontSizeVal = widget.controller!.fontSizeVal;
// 弹幕速度
double danmakuDurationVal = widget.controller!.danmakuDurationVal;
// 弹幕描边
double strokeWidth = widget.controller!.strokeWidth;

final DanmakuController danmakuController =
widget.controller!.danmakuController!;
Expand Down Expand Up @@ -857,6 +860,44 @@ class _HeaderControlState extends State<HeaderControl> {
),
),
),
Text('描边粗细 $strokeWidth'),
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,
value: strokeWidth,
divisions: 6,
label: '$strokeWidth',
onChanged: (double val) {
strokeWidth = val;
widget.controller!.strokeWidth = val;
setState(() {});
try {
final DanmakuOption currentOption =
danmakuController.option;
final DanmakuOption updatedOption =
currentOption.copyWith(strokeWidth: val);
danmakuController.updateOption(updatedOption);
} catch (_) {}
},
),
),
),
Text('字体大小 ${(fontSizeVal * 100).toStringAsFixed(1)}%'),
Padding(
padding: const EdgeInsets.only(
Expand Down
5 changes: 5 additions & 0 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class PlPlayerController {
late double showArea;
late double opacityVal;
late double fontSizeVal;
late double strokeWidth;
late double danmakuDurationVal;
late List<double> speedsList;
// 缓存
Expand Down Expand Up @@ -276,6 +277,9 @@ class PlPlayerController {
// 弹幕时间
danmakuDurationVal =
localCache.get(LocalCacheKey.danmakuDuration, defaultValue: 4.0);
// 描边粗细
strokeWidth =
localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
playRepeat = PlayRepeat.values.toList().firstWhere(
(e) =>
e.value ==
Expand Down Expand Up @@ -1087,6 +1091,7 @@ class PlPlayerController {
localCache.put(LocalCacheKey.danmakuOpacity, opacityVal);
localCache.put(LocalCacheKey.danmakuFontScale, fontSizeVal);
localCache.put(LocalCacheKey.danmakuDuration, danmakuDurationVal);
localCache.put(LocalCacheKey.strokeWidth, strokeWidth);
if (_videoPlayerController != null) {
var pp = _videoPlayerController!.platform as NativePlayer;
await pp.setProperty('audio-files', '');
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ class LocalCacheKey {
wbiKeys = 'wbiKeys',
timeStamp = 'timeStamp',

// 弹幕相关设置 屏蔽类型 显示区域 透明度 字体大小 弹幕时间
// 弹幕相关设置 屏蔽类型 显示区域 透明度 字体大小 弹幕时间 描边粗细
danmakuBlockType = 'danmakuBlockType',
danmakuShowArea = 'danmakuShowArea',
danmakuOpacity = 'danmakuOpacity',
danmakuFontScale = 'danmakuFontScale',
danmakuDuration = 'danmakuDuration',
strokeWidth = 'strokeWidth',

// 代理host port
systemProxyHost = 'systemProxyHost',
Expand Down

0 comments on commit 5f299d9

Please sign in to comment.