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

View File

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

View File

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

View File

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

View File

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

View File

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