Skip to content

Commit 144cc8b

Browse files
committed
修复剧集页弹幕数据无法正常更新的问题
1 parent e8fb8bb commit 144cc8b

File tree

4 files changed

+67
-50
lines changed

4 files changed

+67
-50
lines changed

CHANGELOG.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# 20.2.10
66

7+
- 修复剧集页弹幕数据无法正常更新的问题
8+
79
# 20.2.9
810

911
- 修复编译问题

lib/player/player_video_desktop.dart

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import 'package:win32/win32.dart';
3535
/// basic on dart_vlc.
3636
class DesktopVideoPlayer extends StatefulWidget {
3737
Function? onFullScreenChange;
38+
Function(int count)? onDanmukuPoolInitialed;
3839

39-
DesktopVideoPlayer({super.key, this.onFullScreenChange});
40+
DesktopVideoPlayer(
41+
{super.key, this.onFullScreenChange, this.onDanmukuPoolInitialed});
4042

4143
@override
4244
State<StatefulWidget> createState() {
@@ -170,12 +172,6 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
170172
setState(() {});
171173
}
172174

173-
Future<int> getDanmuCount() async {
174-
await _initDanmukuPool();
175-
return _commentEpisodes.length;
176-
}
177-
178-
179175
void setSubTitle(String subTitle) {
180176
_subTitle = subTitle;
181177
setState(() {});
@@ -219,11 +215,15 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
219215
.commentEpisodeId(searchEpisodeDetails.episodeId, 1);
220216
if (commentEpIdResp == null || commentEpIdResp.count == 0) return;
221217
_commentEpisodes.addAll(commentEpIdResp.comments);
218+
219+
widget.onDanmukuPoolInitialed?.call(_commentEpisodes.length);
222220
}
223221

224222
void _checkAndAddDanmuku(Duration lastPosition, Duration currentPosition) {
225223
for (CommentEpisode commentEp in List.from(_commentEpisodes)) {
226-
if (!commentEp.p.contains(',') || commentEp.p.split(',').length != 4)
224+
if (!commentEp.p.contains(',') || commentEp.p
225+
.split(',')
226+
.length != 4)
227227
continue;
228228
String timeStr = commentEp.p.split(",")[0];
229229
double timeD = double.parse(timeStr);
@@ -249,7 +249,9 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
249249
}
250250

251251
void _addDanmuku(CommentEpisode commentEp) {
252-
if (!commentEp.p.contains(',') || commentEp.p.split(',').length != 4) {
252+
if (!commentEp.p.contains(',') || commentEp.p
253+
.split(',')
254+
.length != 4) {
253255
return;
254256
}
255257
String danmuMode = commentEp.p.split(',')[1];
@@ -578,8 +580,14 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
578580
builder: (context) {
579581
return SizedBox(
580582
height:
581-
MediaQuery.of(context).size.height * (_isFullScreen ? 0.5 : 0.8),
582-
width: MediaQuery.of(context).size.width * 0.8,
583+
MediaQuery
584+
.of(context)
585+
.size
586+
.height * (_isFullScreen ? 0.5 : 0.8),
587+
width: MediaQuery
588+
.of(context)
589+
.size
590+
.width * 0.8,
583591
child: Padding(
584592
padding: const EdgeInsets.only(top: 10, left: 20, right: 20),
585593
child: Column(
@@ -724,7 +732,6 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
724732
return value / devicePixelRatio; // 将Win32的物理像素转为Flutter的逻辑像素
725733
}
726734

727-
728735
@override
729736
Widget build(BuildContext context) {
730737
return GestureDetector(
@@ -767,7 +774,8 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
767774
}
768775
},
769776
child: KeyboardListener(
770-
focusNode: FocusNode()..requestFocus(),
777+
focusNode: FocusNode()
778+
..requestFocus(),
771779
onKeyEvent: _handleKeyEvent,
772780
autofocus: true,
773781
child: MouseRegion(
@@ -798,22 +806,22 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
798806
builder: (context, loading, child) {
799807
return loading
800808
? const Center(
801-
child: Column(
802-
mainAxisAlignment: MainAxisAlignment.center,
803-
children: [
804-
CircularProgressIndicator(
805-
color: Colors.white,
806-
),
807-
SizedBox(height: 10),
808-
Text(
809-
"正在缓冲中...",
810-
style: TextStyle(
811-
color: Colors.white,
812-
fontSize: 10,
813-
decoration: TextDecoration.none),
814-
)
815-
],
816-
)) // 在视频正中心显示加载指示器
809+
child: Column(
810+
mainAxisAlignment: MainAxisAlignment.center,
811+
children: [
812+
CircularProgressIndicator(
813+
color: Colors.white,
814+
),
815+
SizedBox(height: 10),
816+
Text(
817+
"正在缓冲中...",
818+
style: TextStyle(
819+
color: Colors.white,
820+
fontSize: 10,
821+
decoration: TextDecoration.none),
822+
)
823+
],
824+
)) // 在视频正中心显示加载指示器
817825
: const SizedBox.shrink();
818826
},
819827
),
@@ -946,7 +954,7 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
946954
timeLabelLocation: TimeLabelLocation.sides,
947955
timeLabelType: TimeLabelType.totalTime,
948956
timeLabelTextStyle:
949-
const TextStyle(color: Colors.white),
957+
const TextStyle(color: Colors.white),
950958
onSeek: (duration) {
951959
seek(duration);
952960
},
@@ -1082,17 +1090,18 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
10821090
.audioTrackDescription()
10831091
.where((track) => !track.startsWith("-1"))
10841092
.map(
1085-
(track) => PopupMenuItem(
1093+
(track) =>
1094+
PopupMenuItem(
10861095
value: track,
10871096
child: Text(track,
10881097
style: TextStyle(
10891098
fontSize: 14.0,
10901099
color: audioTrack ==
1091-
_getTrackDescId(track)
1100+
_getTrackDescId(track)
10921101
? Colors.lightBlueAccent
10931102
: Colors.black)),
10941103
),
1095-
)
1104+
)
10961105
.toList();
10971106
},
10981107
),
@@ -1102,7 +1111,8 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
11021111
PopupMenuButton(
11031112
iconSize: 24,
11041113
tooltip: "字幕轨道",
1105-
icon: const Icon(Icons.subtitles, color: Colors.white),
1114+
icon: const Icon(Icons.subtitles,
1115+
color: Colors.white),
11061116
onSelected: (String trackDesc) {
11071117
if (trackDesc == "" || !trackDesc.contains(":"))
11081118
return;
@@ -1115,27 +1125,30 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
11151125
return _player
11161126
.spuTrackDescription()
11171127
.map(
1118-
(track) => PopupMenuItem(
1128+
(track) =>
1129+
PopupMenuItem(
11191130
value: track,
11201131
child: Text(track,
11211132
style: TextStyle(
11221133
fontSize: 14.0,
11231134
color: track.startsWith(
1124-
spu.toString())
1135+
spu.toString())
11251136
? Colors.lightBlueAccent
11261137
: Colors.black)),
11271138
),
1128-
)
1139+
)
11291140
.toList();
11301141
},
11311142
),
11321143

11331144
// 右下角小窗置顶
11341145
IconButton(
1135-
onPressed: isLoading.value ? null : _switchSmallScreen,
1146+
onPressed:
1147+
isLoading.value ? null : _switchSmallScreen,
11361148
icon: Icon(
11371149
Icons.picture_in_picture_alt_outlined,
1138-
color: isLoading.value ? Colors.grey : Colors.white,
1150+
color:
1151+
isLoading.value ? Colors.grey : Colors.white,
11391152
),
11401153
),
11411154

lib/player/player_video_mobile.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import 'package:wakelock_plus/wakelock_plus.dart';
3434
/// basic on flutter_vlc_player.
3535
class MobileVideoPlayer extends StatefulWidget {
3636
Function? onFullScreenChange;
37+
Function(int count)? onDanmukuPoolInitialed;
3738

38-
MobileVideoPlayer({super.key, this.onFullScreenChange});
39+
MobileVideoPlayer({super.key, this.onFullScreenChange, this.onDanmukuPoolInitialed});
3940

4041
@override
4142
State<StatefulWidget> createState() {
@@ -169,11 +170,6 @@ class MobileVideoPlayerState extends State<MobileVideoPlayer>
169170
setState(() {});
170171
}
171172

172-
Future<int> getDanmuCount() async {
173-
_initDanmukuPool();
174-
return _commentEpisodes.length;
175-
}
176-
177173
void setSubTitle(String subTitle) {
178174
_subTitle = subTitle;
179175
setState(() {});
@@ -304,6 +300,7 @@ class MobileVideoPlayerState extends State<MobileVideoPlayer>
304300
.commentEpisodeId(searchEpisodeDetails.episodeId, 1);
305301
if (commentEpIdResp == null || commentEpIdResp.count == 0) return;
306302
_commentEpisodes.addAll(commentEpIdResp.comments);
303+
widget.onDanmukuPoolInitialed?.call(_commentEpisodes.length);
307304
}
308305

309306
void addSlave(String url, bool select) {

lib/subject/episode.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,6 @@ class _SubjectEpisodesState extends State<SubjectEpisodesPage> {
536536
_mobilePlayer.currentState?.setProgress(progress);
537537
}
538538
_mobilePlayer.currentState?.reload(videUrl, autoPlay: true);
539-
_danmuCount = await _mobilePlayer.currentState?.getDanmuCount() ?? 0;
540-
setState(() {});
541539
return;
542540
}
543541

@@ -547,9 +545,6 @@ class _SubjectEpisodesState extends State<SubjectEpisodesPage> {
547545
_desktopPlayer.currentState?.setEpisodeId(episodeRecord.episode.id);
548546
_desktopPlayer.currentState?.reload(videUrl, autoStart: true);
549547

550-
_danmuCount = await _desktopPlayer.currentState?.getDanmuCount() ?? 0;
551-
setState(() {});
552-
553548
if (subtitleUrls.isNotEmpty) {
554549
for (var subtitle in subtitleUrls) {
555550
_desktopPlayer.currentState
@@ -642,6 +637,11 @@ class _SubjectEpisodesState extends State<SubjectEpisodesPage> {
642637
_isFullScreen = !_isFullScreen;
643638
});
644639
},
640+
onDanmukuPoolInitialed: (int count){
641+
setState(() {
642+
_danmuCount = count;
643+
});
644+
},
645645
)
646646
: DesktopVideoPlayer(
647647
key: _desktopPlayer,
@@ -650,6 +650,11 @@ class _SubjectEpisodesState extends State<SubjectEpisodesPage> {
650650
_isFullScreen = !_isFullScreen;
651651
});
652652
},
653+
onDanmukuPoolInitialed: (int count){
654+
setState(() {
655+
_danmuCount = count;
656+
});
657+
},
653658
),
654659
);
655660
}

0 commit comments

Comments
 (0)