mod: 设置弹幕开关
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:ns_danmaku/ns_danmaku.dart';
|
||||
import 'package:pilipala/pages/danmaku/index.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
import 'package:pilipala/utils/danmaku.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
/// 传入播放器控制器,监听播放进度,加载对应弹幕
|
||||
class PlDanmaku extends StatefulWidget {
|
||||
@ -25,22 +27,37 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
late PlDanmakuController _plDanmakuController;
|
||||
DanmakuController? _controller;
|
||||
bool danmuPlayStatus = true;
|
||||
Box setting = GStrorage.setting;
|
||||
late bool enableShowDanmaku;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
enableShowDanmaku =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
_plDanmakuController =
|
||||
PlDanmakuController(widget.cid, widget.playerController);
|
||||
if (mounted) {
|
||||
playerController = widget.playerController;
|
||||
_plDanmakuController.videoDuration = playerController.duration.value;
|
||||
_plDanmakuController
|
||||
..calcSegment()
|
||||
..queryDanmaku();
|
||||
if (enableShowDanmaku || playerController.isOpenDanmu.value) {
|
||||
_plDanmakuController
|
||||
..calcSegment()
|
||||
..queryDanmaku();
|
||||
}
|
||||
playerController
|
||||
..addStatusLister(playerListener)
|
||||
..addPositionListener(videoPositionListen);
|
||||
}
|
||||
playerController.isOpenDanmu.listen((p0) {
|
||||
if (p0) {
|
||||
if (_plDanmakuController.dmSegList.isEmpty) {
|
||||
_plDanmakuController
|
||||
..calcSegment()
|
||||
..queryDanmaku();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 播放器状态监听
|
||||
@ -61,6 +78,9 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
PlDanmakuController ctr = _plDanmakuController;
|
||||
int currentPosition = position.inMilliseconds;
|
||||
|
||||
if (!playerController.isOpenDanmu.value) {
|
||||
return;
|
||||
}
|
||||
// 超出分段数返回
|
||||
if (ctr.currentSegIndex >= ctr.dmSegList.length) {
|
||||
return;
|
||||
|
@ -108,6 +108,12 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
setKey: SettingBoxKey.enableQuickDouble,
|
||||
defaultVal: true,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '弹幕开关',
|
||||
subTitle: '展示弹幕',
|
||||
setKey: SettingBoxKey.enableShowDanmaku,
|
||||
defaultVal: false,
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('默认画质', style: titleStyle),
|
||||
|
@ -196,13 +196,15 @@ class PlPlayerController {
|
||||
Rx<String> get videoType => _videoType;
|
||||
|
||||
/// 弹幕开关
|
||||
Rx<bool> isOpenDanmu = true.obs;
|
||||
Rx<bool> isOpenDanmu = false.obs;
|
||||
// 关联弹幕控制器
|
||||
DanmakuController? danmakuController;
|
||||
|
||||
// 添加一个私有构造函数
|
||||
PlPlayerController._() {
|
||||
_videoType = videoType;
|
||||
isOpenDanmu.value =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
|
||||
// if (status == PlayerStatus.playing) {
|
||||
// WakelockPlus.enable();
|
||||
|
@ -101,6 +101,7 @@ class SettingBoxKey {
|
||||
static const String enableAutoExit = 'enableAutoExit';
|
||||
// youtube 双击快进快退
|
||||
static const String enableQuickDouble = 'enableQuickDouble';
|
||||
static const String enableShowDanmaku = 'enableShowDanmaku';
|
||||
|
||||
/// 隐私
|
||||
static const String blackMidsList = 'blackMidsList';
|
||||
|
Reference in New Issue
Block a user