feat: static dm duration

Closes #479

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-03-25 17:44:24 +08:00
parent 8030912087
commit d4e4813c78
6 changed files with 102 additions and 49 deletions

View File

@@ -138,8 +138,8 @@ class _PlDanmakuState extends State<PlDanmaku> {
double _getFontSize(isFullScreen) =>
isFullScreen == false || widget.isPipMode == true
? 15 * playerController.fontSizeVal
: 15 * playerController.fontSizeFSVal;
? 15 * playerController.fontSize
: 15 * playerController.fontSizeFS;
@override
Widget build(BuildContext context) {
@@ -157,11 +157,13 @@ class _PlDanmakuState extends State<PlDanmaku> {
fontSize: _getFontSize(playerController.isFullScreen.value),
fontWeight: playerController.fontWeight,
area: playerController.showArea,
opacity: playerController.opacityVal,
opacity: playerController.opacity,
hideTop: playerController.blockTypes.contains(5),
hideScroll: playerController.blockTypes.contains(2),
hideBottom: playerController.blockTypes.contains(4),
duration: playerController.danmakuDurationVal ~/
duration: playerController.danmakuDuration ~/
playerController.playbackSpeed,
staticDuration: playerController.danmakuStaticDuration ~/
playerController.playbackSpeed,
strokeWidth: playerController.strokeWidth,
lineHeight: playerController.danmakuLineHeight,

View File

@@ -96,8 +96,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
double _getFontSize(isFullScreen) {
return isFullScreen == false || _isPipMode == true
? 15 * plPlayerController.fontSizeVal
: 15 * plPlayerController.fontSizeFSVal;
? 15 * plPlayerController.fontSize
: 15 * plPlayerController.fontSizeFS;
}
void videoSourceInit() {
@@ -176,12 +176,15 @@ class _LiveRoomPageState extends State<LiveRoomPage>
fontSize: _getFontSize(isFullScreen),
fontWeight: plPlayerController.fontWeight,
area: plPlayerController.showArea,
opacity: plPlayerController.opacityVal,
opacity: plPlayerController.opacity,
hideTop: plPlayerController.blockTypes.contains(5),
hideScroll: plPlayerController.blockTypes.contains(2),
hideBottom: plPlayerController.blockTypes.contains(4),
duration: plPlayerController.danmakuDurationVal ~/
duration: plPlayerController.danmakuDuration ~/
plPlayerController.playbackSpeed,
staticDuration:
plPlayerController.danmakuStaticDuration ~/
plPlayerController.playbackSpeed,
strokeWidth: plPlayerController.strokeWidth,
lineHeight: plPlayerController.danmakuLineHeight,
),

View File

@@ -1453,14 +1453,15 @@ class _HeaderControlState extends State<HeaderControl> {
// 显示区域
double showArea = widget.controller.showArea;
// 不透明度
double opacityVal = widget.controller.opacityVal;
double opacity = widget.controller.opacity;
// 字体大小
double fontSizeVal = widget.controller.fontSizeVal;
double fontSize = widget.controller.fontSize;
// 全屏字体大小
double fontSizeFSVal = widget.controller.fontSizeFSVal;
double fontSizeFS = widget.controller.fontSizeFS;
double danmakuLineHeight = widget.controller.danmakuLineHeight;
// 弹幕速度
double danmakuDurationVal = widget.controller.danmakuDurationVal;
double danmakuDuration = widget.controller.danmakuDuration;
double danmakuStaticDuration = widget.controller.danmakuStaticDuration;
// 弹幕描边
double strokeWidth = widget.controller.strokeWidth;
// 字体粗细
@@ -1499,31 +1500,46 @@ class _HeaderControlState extends State<HeaderControl> {
}
void updateDuration(double val) {
danmakuDurationVal = val;
danmakuDuration = val;
widget.controller
..danmakuDurationVal = danmakuDurationVal
..danmakuDuration = danmakuDuration
..putDanmakuSettings();
setState(() {});
try {
danmakuController?.updateOption(
danmakuController.option.copyWith(
duration:
danmakuDurationVal ~/ widget.controller.playbackSpeed),
danmakuDuration ~/ widget.controller.playbackSpeed),
);
} catch (_) {}
}
void updateStaticDuration(double val) {
danmakuStaticDuration = val;
widget.controller
..danmakuStaticDuration = danmakuStaticDuration
..putDanmakuSettings();
setState(() {});
try {
danmakuController?.updateOption(
danmakuController.option.copyWith(
staticDuration: danmakuStaticDuration ~/
widget.controller.playbackSpeed),
);
} catch (_) {}
}
void updateFontSizeFS(double val) {
fontSizeFSVal = val;
fontSizeFS = val;
widget.controller
..fontSizeFSVal = fontSizeFSVal
..fontSizeFS = fontSizeFS
..putDanmakuSettings();
setState(() {});
if (widget.controller.isFullScreen.value == true) {
try {
danmakuController?.updateOption(
danmakuController.option.copyWith(
fontSize: (15 * fontSizeFSVal).toDouble(),
fontSize: (15 * fontSizeFS).toDouble(),
),
);
} catch (_) {}
@@ -1531,16 +1547,16 @@ class _HeaderControlState extends State<HeaderControl> {
}
void updateFontSize(double val) {
fontSizeVal = val;
fontSize = val;
widget.controller
..fontSizeVal = fontSizeVal
..fontSize = fontSize
..putDanmakuSettings();
setState(() {});
if (widget.controller.isFullScreen.value == false) {
try {
danmakuController?.updateOption(
danmakuController.option.copyWith(
fontSize: (15 * fontSizeVal).toDouble(),
fontSize: (15 * fontSize).toDouble(),
),
);
} catch (_) {}
@@ -1574,9 +1590,9 @@ class _HeaderControlState extends State<HeaderControl> {
}
void updateOpacity(double val) {
opacityVal = val;
opacity = val;
widget.controller
..opacityVal = opacityVal
..opacity = opacity
..putDanmakuSettings();
setState(() {});
try {
@@ -1751,7 +1767,7 @@ class _HeaderControlState extends State<HeaderControl> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('不透明度 ${opacityVal * 100}%'),
Text('不透明度 ${opacity * 100}%'),
resetBtn('100.0%', () => updateOpacity(1.0)),
],
),
@@ -1767,9 +1783,9 @@ class _HeaderControlState extends State<HeaderControl> {
child: Slider(
min: 0,
max: 1,
value: opacityVal,
value: opacity,
divisions: 10,
label: '${opacityVal * 100}%',
label: '${opacity * 100}%',
onChanged: updateOpacity,
),
),
@@ -1831,7 +1847,7 @@ class _HeaderControlState extends State<HeaderControl> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('字体大小 ${(fontSizeVal * 100).toStringAsFixed(1)}%'),
Text('字体大小 ${(fontSize * 100).toStringAsFixed(1)}%'),
resetBtn('100.0%', () => updateFontSize(1.0)),
],
),
@@ -1847,9 +1863,9 @@ class _HeaderControlState extends State<HeaderControl> {
child: Slider(
min: 0.5,
max: 2.5,
value: fontSizeVal,
value: fontSize,
divisions: 20,
label: '${(fontSizeVal * 100).toStringAsFixed(1)}%',
label: '${(fontSize * 100).toStringAsFixed(1)}%',
onChanged: updateFontSize,
),
),
@@ -1858,7 +1874,7 @@ class _HeaderControlState extends State<HeaderControl> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'全屏字体大小 ${(fontSizeFSVal * 100).toStringAsFixed(1)}%'),
'全屏字体大小 ${(fontSizeFS * 100).toStringAsFixed(1)}%'),
resetBtn('120.0%', () => updateFontSizeFS(1.2)),
],
),
@@ -1874,9 +1890,9 @@ class _HeaderControlState extends State<HeaderControl> {
child: Slider(
min: 0.5,
max: 2.5,
value: fontSizeFSVal,
value: fontSizeFS,
divisions: 20,
label: '${(fontSizeFSVal * 100).toStringAsFixed(1)}%',
label: '${(fontSizeFS * 100).toStringAsFixed(1)}%',
onChanged: updateFontSizeFS,
),
),
@@ -1884,7 +1900,7 @@ class _HeaderControlState extends State<HeaderControl> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('弹幕时长 $danmakuDurationVal'),
Text('滚动弹幕时长 $danmakuDuration'),
resetBtn(7.0, () => updateDuration(7.0)),
],
),
@@ -1900,15 +1916,43 @@ class _HeaderControlState extends State<HeaderControl> {
child: Slider(
min: 1,
max: 50,
value: danmakuDurationVal,
value: danmakuDuration,
divisions: 49,
label: danmakuDurationVal.toString(),
label: danmakuDuration.toString(),
onChanged: (double val) {
updateDuration(val.toPrecision(1));
},
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('静态弹幕时长 $danmakuStaticDuration'),
resetBtn(4.0, () => updateStaticDuration(4.0)),
],
),
Padding(
padding: const EdgeInsets.only(
top: 0,
bottom: 6,
left: 10,
right: 10,
),
child: SliderTheme(
data: sliderTheme,
child: Slider(
min: 1,
max: 50,
value: danmakuStaticDuration,
divisions: 49,
label: danmakuStaticDuration.toString(),
onChanged: (double val) {
updateStaticDuration(val.toPrecision(1));
},
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [

View File

@@ -270,13 +270,14 @@ class PlPlayerController {
// 弹幕相关配置
late List blockTypes;
late double showArea;
late double opacityVal;
late double fontSizeVal;
late double fontSizeFSVal;
late double opacity;
late double fontSize;
late double fontSizeFS;
late double strokeWidth;
late int fontWeight;
late bool massiveMode;
late double danmakuDurationVal;
late double danmakuDuration;
late double danmakuStaticDuration;
late List<double> speedList;
double? defaultDuration;
late bool enableAutoLongPressSpeed = false;
@@ -409,18 +410,19 @@ class PlPlayerController {
blockTypes = setting.get(SettingBoxKey.danmakuBlockType, defaultValue: []);
showArea = setting.get(SettingBoxKey.danmakuShowArea, defaultValue: 0.5);
// 不透明度
opacityVal = setting.get(SettingBoxKey.danmakuOpacity, defaultValue: 1.0);
opacity = setting.get(SettingBoxKey.danmakuOpacity, defaultValue: 1.0);
// 字体大小
fontSizeVal =
setting.get(SettingBoxKey.danmakuFontScale, defaultValue: 1.0);
fontSize = setting.get(SettingBoxKey.danmakuFontScale, defaultValue: 1.0);
// 全屏字体大小
fontSizeFSVal = GStorage.danmakuFontScaleFS;
fontSizeFS = GStorage.danmakuFontScaleFS;
subtitleFontScale = GStorage.subtitleFontScale;
subtitleFontScaleFS = GStorage.subtitleFontScaleFS;
massiveMode = GStorage.danmakuMassiveMode;
// 弹幕时间
danmakuDurationVal =
danmakuDuration =
setting.get(SettingBoxKey.danmakuDuration, defaultValue: 7.0);
danmakuStaticDuration =
setting.get(SettingBoxKey.danmakuStaticDuration, defaultValue: 4.0);
// 描边粗细
strokeWidth = setting.get(SettingBoxKey.strokeWidth, defaultValue: 1.5);
// 弹幕字体粗细
@@ -1509,10 +1511,11 @@ class PlPlayerController {
setting.put(SettingBoxKey.danmakuWeight, danmakuWeight);
setting.put(SettingBoxKey.danmakuBlockType, blockTypes);
setting.put(SettingBoxKey.danmakuShowArea, showArea);
setting.put(SettingBoxKey.danmakuOpacity, opacityVal);
setting.put(SettingBoxKey.danmakuFontScale, fontSizeVal);
setting.put(SettingBoxKey.danmakuFontScaleFS, fontSizeFSVal);
setting.put(SettingBoxKey.danmakuDuration, danmakuDurationVal);
setting.put(SettingBoxKey.danmakuOpacity, opacity);
setting.put(SettingBoxKey.danmakuFontScale, fontSize);
setting.put(SettingBoxKey.danmakuFontScaleFS, fontSizeFS);
setting.put(SettingBoxKey.danmakuDuration, danmakuDuration);
setting.put(SettingBoxKey.danmakuStaticDuration, danmakuStaticDuration);
setting.put(SettingBoxKey.strokeWidth, strokeWidth);
setting.put(SettingBoxKey.fontWeight, fontWeight);
setting.put(SettingBoxKey.danmakuLineHeight, danmakuLineHeight);

View File

@@ -741,6 +741,7 @@ class SettingBoxKey {
danmakuFontScale = 'danmakuFontScale',
danmakuFontScaleFS = 'danmakuFontScaleFS',
danmakuDuration = 'danmakuDuration',
danmakuStaticDuration = 'danmakuStaticDuration',
danmakuMassiveMode = 'danmakuMassiveMode',
danmakuLineHeight = 'danmakuLineHeight',
strokeWidth = 'strokeWidth',

View File

@@ -252,7 +252,7 @@ packages:
description:
path: "."
ref: main
resolved-ref: "4fb1d2d15fa84d28aae45aa2324beb7f230c045c"
resolved-ref: "5391050a7e070a85234762edadc93298c6ed6523"
url: "https://github.com/bggRGjQaUbCoE/canvas_danmaku.git"
source: git
version: "0.2.6"