mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: merge danmaku in loop (#813)
This commit is contained in:
committed by
GitHub
parent
a49caa871d
commit
07d2b3b464
@@ -6,15 +6,16 @@ class PlDanmakuController {
|
||||
PlDanmakuController(
|
||||
this.cid,
|
||||
this.plPlayerController,
|
||||
);
|
||||
) : mergeDanmaku = plPlayerController.mergeDanmaku;
|
||||
final int cid;
|
||||
final PlPlayerController plPlayerController;
|
||||
final bool mergeDanmaku;
|
||||
|
||||
Map<int, List<DanmakuElem>> dmSegMap = {};
|
||||
// 已请求的段落标记
|
||||
Map requestedSeg = {};
|
||||
Set<int> requestedSeg = {};
|
||||
|
||||
static int segmentLength = 60 * 6 * 1000;
|
||||
static const int segmentLength = 60 * 6 * 1000;
|
||||
|
||||
void dispose() {
|
||||
dmSegMap.clear();
|
||||
@@ -26,36 +27,48 @@ class PlDanmakuController {
|
||||
}
|
||||
|
||||
Future<void> queryDanmaku(int segmentIndex) async {
|
||||
if (requestedSeg[segmentIndex] == true) {
|
||||
if (requestedSeg.contains(segmentIndex)) {
|
||||
return;
|
||||
}
|
||||
requestedSeg[segmentIndex] = true;
|
||||
final Map result = await DanmakuHttp.queryDanmaku(
|
||||
requestedSeg.add(segmentIndex);
|
||||
final result = await DanmakuHttp.queryDanmaku(
|
||||
cid: cid,
|
||||
segmentIndex: segmentIndex + 1,
|
||||
mergeDanmaku: plPlayerController.mergeDanmaku,
|
||||
);
|
||||
if (result['status']) {
|
||||
if (result['data'].elems.isNotEmpty) {
|
||||
for (DanmakuElem element in result['data'].elems) {
|
||||
if (element.mode == 7 && !plPlayerController.showSpecialDanmaku) {
|
||||
continue;
|
||||
|
||||
if (result.isSuccess) {
|
||||
final data = result.data;
|
||||
if (data.elems.isNotEmpty) {
|
||||
final Map<String, int> counts = {};
|
||||
if (mergeDanmaku) {
|
||||
data.elems.retainWhere((item) {
|
||||
int? count = counts[item.content];
|
||||
counts[item.content] = count != null ? count + 1 : 1;
|
||||
return count == null;
|
||||
});
|
||||
}
|
||||
|
||||
for (final element in data.elems) {
|
||||
if (mergeDanmaku) {
|
||||
final count = counts[element.content];
|
||||
if (count != 1) {
|
||||
element.attr = count!;
|
||||
} else {
|
||||
element.clearAttr();
|
||||
}
|
||||
}
|
||||
int pos = element.progress ~/ 100; //每0.1秒存储一次
|
||||
if (dmSegMap[pos] == null) {
|
||||
dmSegMap[pos] = [];
|
||||
}
|
||||
dmSegMap[pos]!.add(element);
|
||||
(dmSegMap[pos] ??= []).add(element);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requestedSeg[segmentIndex] = false;
|
||||
requestedSeg.remove(segmentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
List<DanmakuElem>? getCurrentDanmaku(int progress) {
|
||||
int segmentIndex = calcSegment(progress);
|
||||
if (requestedSeg[segmentIndex] != true) {
|
||||
if (!requestedSeg.contains(segmentIndex)) {
|
||||
queryDanmaku(segmentIndex);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1264,13 +1264,13 @@ class HeaderControlState extends State<HeaderControl> {
|
||||
/// 弹幕功能
|
||||
void showSetDanmaku() {
|
||||
// 屏蔽类型
|
||||
const List<Map<String, dynamic>> blockTypesList = [
|
||||
{'value': 5, 'label': '顶部'},
|
||||
{'value': 2, 'label': '滚动'},
|
||||
{'value': 4, 'label': '底部'},
|
||||
{'value': 6, 'label': '彩色'},
|
||||
const List<({int value, String label})> blockTypesList = [
|
||||
(value: 5, label: '顶部'),
|
||||
(value: 2, label: '滚动'),
|
||||
(value: 4, label: '底部'),
|
||||
(value: 6, label: '彩色'),
|
||||
];
|
||||
final List blockTypes = widget.controller.blockTypes;
|
||||
final blockTypes = widget.controller.blockTypes;
|
||||
// 智能云屏蔽
|
||||
int danmakuWeight = widget.controller.danmakuWeight;
|
||||
// 显示区域
|
||||
@@ -1501,16 +1501,14 @@ class HeaderControlState extends State<HeaderControl> {
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final Map<String, dynamic> i
|
||||
for (final (value: value, label: label)
|
||||
in blockTypesList) ...[
|
||||
ActionRowLineItem(
|
||||
onTap: () {
|
||||
final bool isChoose =
|
||||
blockTypes.contains(i['value']);
|
||||
if (isChoose) {
|
||||
blockTypes.remove(i['value']);
|
||||
if (blockTypes.contains(value)) {
|
||||
blockTypes.remove(value);
|
||||
} else {
|
||||
blockTypes.add(i['value']);
|
||||
blockTypes.add(value);
|
||||
}
|
||||
widget.controller
|
||||
..blockTypes = blockTypes
|
||||
@@ -1527,8 +1525,8 @@ class HeaderControlState extends State<HeaderControl> {
|
||||
);
|
||||
} catch (_) {}
|
||||
},
|
||||
text: i['label'],
|
||||
selectStatus: blockTypes.contains(i['value']),
|
||||
text: label,
|
||||
selectStatus: blockTypes.contains(value),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user