Skip to content

Commit

Permalink
fix: 弹幕控制器获取不到视频时间时异常
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Mar 2, 2024
1 parent 1209a86 commit 0d46ebb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/pages/danmaku/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class PlDanmakuController {
static int segmentLength = 60 * 6 * 1000;

void initiate(int videoDuration, int progress) {
if (videoDuration <= 0) {
return;
}
if (requestedSeg.isEmpty) {
int segCount = (videoDuration / segmentLength).ceil();
requestedSeg = List<bool>.generate(segCount, (index) => false);
Expand All @@ -30,6 +33,9 @@ class PlDanmakuController {
}

void queryDanmaku(int segmentIndex) async {
if (requestedSeg.length <= segmentIndex) {
return;
}
assert(requestedSeg[segmentIndex] == false);
requestedSeg[segmentIndex] = true;
final DmSegMobileReply result = await DanmakaHttp.queryDanmaku(
Expand All @@ -47,6 +53,9 @@ class PlDanmakuController {

List<DanmakuElem>? getCurrentDanmaku(int progress) {
int segmentIndex = calcSegment(progress);
if (requestedSeg.length <= segmentIndex) {
return <DanmakuElem>[];
}
if (!requestedSeg[segmentIndex]) {
queryDanmaku(segmentIndex);
}
Expand Down

0 comments on commit 0d46ebb

Please sign in to comment.