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