@@ -35,8 +35,10 @@ import 'package:win32/win32.dart';
35
35
/// basic on dart_vlc.
36
36
class DesktopVideoPlayer extends StatefulWidget {
37
37
Function ? onFullScreenChange;
38
+ Function (int count)? onDanmukuPoolInitialed;
38
39
39
- DesktopVideoPlayer ({super .key, this .onFullScreenChange});
40
+ DesktopVideoPlayer (
41
+ {super .key, this .onFullScreenChange, this .onDanmukuPoolInitialed});
40
42
41
43
@override
42
44
State <StatefulWidget > createState () {
@@ -170,12 +172,6 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
170
172
setState (() {});
171
173
}
172
174
173
- Future <int > getDanmuCount () async {
174
- await _initDanmukuPool ();
175
- return _commentEpisodes.length;
176
- }
177
-
178
-
179
175
void setSubTitle (String subTitle) {
180
176
_subTitle = subTitle;
181
177
setState (() {});
@@ -219,11 +215,15 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
219
215
.commentEpisodeId (searchEpisodeDetails.episodeId, 1 );
220
216
if (commentEpIdResp == null || commentEpIdResp.count == 0 ) return ;
221
217
_commentEpisodes.addAll (commentEpIdResp.comments);
218
+
219
+ widget.onDanmukuPoolInitialed? .call (_commentEpisodes.length);
222
220
}
223
221
224
222
void _checkAndAddDanmuku (Duration lastPosition, Duration currentPosition) {
225
223
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 )
227
227
continue ;
228
228
String timeStr = commentEp.p.split ("," )[0 ];
229
229
double timeD = double .parse (timeStr);
@@ -249,7 +249,9 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
249
249
}
250
250
251
251
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 ) {
253
255
return ;
254
256
}
255
257
String danmuMode = commentEp.p.split (',' )[1 ];
@@ -578,8 +580,14 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
578
580
builder: (context) {
579
581
return SizedBox (
580
582
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 ,
583
591
child: Padding (
584
592
padding: const EdgeInsets .only (top: 10 , left: 20 , right: 20 ),
585
593
child: Column (
@@ -724,7 +732,6 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
724
732
return value / devicePixelRatio; // 将Win32的物理像素转为Flutter的逻辑像素
725
733
}
726
734
727
-
728
735
@override
729
736
Widget build (BuildContext context) {
730
737
return GestureDetector (
@@ -767,7 +774,8 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
767
774
}
768
775
},
769
776
child: KeyboardListener (
770
- focusNode: FocusNode ()..requestFocus (),
777
+ focusNode: FocusNode ()
778
+ ..requestFocus (),
771
779
onKeyEvent: _handleKeyEvent,
772
780
autofocus: true ,
773
781
child: MouseRegion (
@@ -798,22 +806,22 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
798
806
builder: (context, loading, child) {
799
807
return loading
800
808
? 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
+ )) // 在视频正中心显示加载指示器
817
825
: const SizedBox .shrink ();
818
826
},
819
827
),
@@ -946,7 +954,7 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
946
954
timeLabelLocation: TimeLabelLocation .sides,
947
955
timeLabelType: TimeLabelType .totalTime,
948
956
timeLabelTextStyle:
949
- const TextStyle (color: Colors .white),
957
+ const TextStyle (color: Colors .white),
950
958
onSeek: (duration) {
951
959
seek (duration);
952
960
},
@@ -1082,17 +1090,18 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
1082
1090
.audioTrackDescription ()
1083
1091
.where ((track) => ! track.startsWith ("-1" ))
1084
1092
.map (
1085
- (track) => PopupMenuItem (
1093
+ (track) =>
1094
+ PopupMenuItem (
1086
1095
value: track,
1087
1096
child: Text (track,
1088
1097
style: TextStyle (
1089
1098
fontSize: 14.0 ,
1090
1099
color: audioTrack ==
1091
- _getTrackDescId (track)
1100
+ _getTrackDescId (track)
1092
1101
? Colors .lightBlueAccent
1093
1102
: Colors .black)),
1094
1103
),
1095
- )
1104
+ )
1096
1105
.toList ();
1097
1106
},
1098
1107
),
@@ -1102,7 +1111,8 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
1102
1111
PopupMenuButton (
1103
1112
iconSize: 24 ,
1104
1113
tooltip: "字幕轨道" ,
1105
- icon: const Icon (Icons .subtitles, color: Colors .white),
1114
+ icon: const Icon (Icons .subtitles,
1115
+ color: Colors .white),
1106
1116
onSelected: (String trackDesc) {
1107
1117
if (trackDesc == "" || ! trackDesc.contains (":" ))
1108
1118
return ;
@@ -1115,27 +1125,30 @@ class DesktopVideoPlayerState extends State<DesktopVideoPlayer>
1115
1125
return _player
1116
1126
.spuTrackDescription ()
1117
1127
.map (
1118
- (track) => PopupMenuItem (
1128
+ (track) =>
1129
+ PopupMenuItem (
1119
1130
value: track,
1120
1131
child: Text (track,
1121
1132
style: TextStyle (
1122
1133
fontSize: 14.0 ,
1123
1134
color: track.startsWith (
1124
- spu.toString ())
1135
+ spu.toString ())
1125
1136
? Colors .lightBlueAccent
1126
1137
: Colors .black)),
1127
1138
),
1128
- )
1139
+ )
1129
1140
.toList ();
1130
1141
},
1131
1142
),
1132
1143
1133
1144
// 右下角小窗置顶
1134
1145
IconButton (
1135
- onPressed: isLoading.value ? null : _switchSmallScreen,
1146
+ onPressed:
1147
+ isLoading.value ? null : _switchSmallScreen,
1136
1148
icon: Icon (
1137
1149
Icons .picture_in_picture_alt_outlined,
1138
- color: isLoading.value ? Colors .grey : Colors .white,
1150
+ color:
1151
+ isLoading.value ? Colors .grey : Colors .white,
1139
1152
),
1140
1153
),
1141
1154
0 commit comments