mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-23 04:00:28 +08:00
@@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/grpc/bilibili/community/service/dm/v1.pb.dart';
|
||||
@@ -14,13 +13,15 @@ import 'package:get/get.dart';
|
||||
class PlDanmaku extends StatefulWidget {
|
||||
final int cid;
|
||||
final PlPlayerController playerController;
|
||||
final bool? isPipMode;
|
||||
final bool isPipMode;
|
||||
final bool isFullScreen;
|
||||
|
||||
const PlDanmaku({
|
||||
super.key,
|
||||
required this.cid,
|
||||
required this.playerController,
|
||||
this.isPipMode,
|
||||
this.isPipMode = false,
|
||||
required this.isFullScreen,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -33,8 +34,6 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
late PlDanmakuController _plDanmakuController;
|
||||
DanmakuController? _controller;
|
||||
int latestAddedPosition = -1;
|
||||
bool? _isFullScreen;
|
||||
StreamSubscription? _listenerFS;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -53,20 +52,27 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
playerController
|
||||
..addStatusLister(playerListener)
|
||||
..addPositionListener(videoPositionListen);
|
||||
_listenerFS = playerController.isFullScreen.listen((isFullScreen) {
|
||||
if (isFullScreen != _isFullScreen) {
|
||||
_isFullScreen = isFullScreen;
|
||||
if (_controller != null) {
|
||||
_controller!.updateOption(
|
||||
_controller!.option.copyWith(
|
||||
fontSize: _getFontSize(isFullScreen),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(PlDanmaku oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.isPipMode != widget.isPipMode ||
|
||||
oldWidget.isFullScreen != widget.isFullScreen) {
|
||||
_updateFontSize();
|
||||
}
|
||||
}
|
||||
|
||||
void _updateFontSize() {
|
||||
_controller?.updateOption(
|
||||
_controller!.option.copyWith(fontSize: _fontSize),
|
||||
);
|
||||
}
|
||||
|
||||
double get _fontSize => !widget.isFullScreen || widget.isPipMode
|
||||
? 15 * playerController.danmakuFontScale
|
||||
: 15 * playerController.danmakuFontScaleFS;
|
||||
|
||||
// 播放器状态监听
|
||||
void playerListener(PlayerStatus? status) {
|
||||
if (status == PlayerStatus.playing) {
|
||||
@@ -77,15 +83,11 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
}
|
||||
|
||||
void videoPositionListen(Duration position) {
|
||||
if (!playerController.enableShowDanmaku.value) {
|
||||
if (_controller == null || !playerController.enableShowDanmaku.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_controller == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!playerController.showDanmaku && widget.isPipMode != true) {
|
||||
if (!playerController.showDanmaku && !widget.isPipMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +140,6 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_listenerFS?.cancel();
|
||||
playerController
|
||||
..removePositionListener(videoPositionListen)
|
||||
..removeStatusLister(playerListener);
|
||||
@@ -146,45 +147,35 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
double _getFontSize(bool isFullScreen) =>
|
||||
!isFullScreen || widget.isPipMode == true
|
||||
? 15 * playerController.danmakuFontScale
|
||||
: 15 * playerController.danmakuFontScaleFS;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) {
|
||||
// double initDuration = box.maxWidth / 12;
|
||||
return Obx(
|
||||
() => AnimatedOpacity(
|
||||
opacity: playerController.enableShowDanmaku.value ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
child: DanmakuScreen(
|
||||
createdController: (DanmakuController e) {
|
||||
playerController.danmakuController = _controller = e;
|
||||
},
|
||||
option: DanmakuOption(
|
||||
fontSize: _getFontSize(playerController.isFullScreen.value),
|
||||
fontWeight: playerController.fontWeight,
|
||||
area: playerController.showArea,
|
||||
opacity: playerController.danmakuOpacity,
|
||||
hideTop: playerController.blockTypes.contains(5),
|
||||
hideScroll: playerController.blockTypes.contains(2),
|
||||
hideBottom: playerController.blockTypes.contains(4),
|
||||
duration:
|
||||
playerController.danmakuDuration /
|
||||
playerController.playbackSpeed,
|
||||
staticDuration:
|
||||
playerController.danmakuStaticDuration /
|
||||
playerController.playbackSpeed,
|
||||
strokeWidth: playerController.strokeWidth,
|
||||
lineHeight: playerController.danmakuLineHeight,
|
||||
),
|
||||
),
|
||||
return Obx(
|
||||
() => AnimatedOpacity(
|
||||
opacity: playerController.enableShowDanmaku.value ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
child: DanmakuScreen(
|
||||
createdController: (DanmakuController e) {
|
||||
playerController.danmakuController = _controller = e;
|
||||
},
|
||||
option: DanmakuOption(
|
||||
fontSize: _fontSize,
|
||||
fontWeight: playerController.fontWeight,
|
||||
area: playerController.showArea,
|
||||
opacity: playerController.danmakuOpacity,
|
||||
hideTop: playerController.blockTypes.contains(5),
|
||||
hideScroll: playerController.blockTypes.contains(2),
|
||||
hideBottom: playerController.blockTypes.contains(4),
|
||||
duration:
|
||||
playerController.danmakuDuration /
|
||||
playerController.playbackSpeed,
|
||||
staticDuration:
|
||||
playerController.danmakuStaticDuration /
|
||||
playerController.playbackSpeed,
|
||||
strokeWidth: playerController.strokeWidth,
|
||||
lineHeight: playerController.danmakuLineHeight,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user