ohos_video_page.dart
8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
import 'package:video_player/video_player.dart';
import '../../../widgets/system_app_bar.dart';
class BumbleBeeRemoteVideo extends StatefulWidget {
const BumbleBeeRemoteVideo(this.url, this.filePath);
final String? filePath;
final String url;
@override
BumbleBeeRemoteVideoState createState() => BumbleBeeRemoteVideoState();
}
class BumbleBeeRemoteVideoState extends State<BumbleBeeRemoteVideo> {
late VideoPlayerController _controller;
// Future<ClosedCaptionFile> _loadCaptions() async {
// final String fileContents = await DefaultAssetBundle.of(context)
// .loadString('assets/bumble_bee_captions.vtt');
// return WebVTTCaptionFile(
// fileContents); // For vtt files, use WebVTTCaptionFile
// }
@override
void initState() {
super.initState();
_controller = VideoPlayerController.networkUrl(
Uri.parse(widget.url),
// Uri.parse(
// 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
// closedCaptionFile: _loadCaptions(),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
// viewType: widget.viewType,
);
_controller.addListener(() {
setState(() {});
});
_controller.setLooping(true);
_controller.initialize();
// _controller.initialize().then((_) {
// // 确保添加了这一行,以便在初始化完成后执行操作
// setState(() {});
// });
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: SystemAppBar("评价管理"),
body: Container(
child: _controller.value.isInitialized
? Center(
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
VideoPlayer(_controller),
// widget.filePath != null
// ? Image.file(
// File(widget.filePath!),
// fit: BoxFit.contain,
// width: ScreenUtil().screenWidth,
// height: ScreenUtil().screenHeight,
// )
// : SizedBox(),
// ClosedCaption(text: _controller.value.caption.text),
_ControlsOverlay(controller: _controller),
VideoProgressIndicator(
_controller,
allowScrubbing: true,
colors: VideoProgressColors(
playedColor: MyColours.color_438E93,
bufferedColor: Colors.black,
backgroundColor: Colors.black),
),
],
),
// AspectRatio(
// aspectRatio: _controller.value.aspectRatio,
// child:
// ),
// Material(
// child: SingleChildScrollView(
// child: Column(
// children: <Widget>[
// // // Container(padding: const EdgeInsets.only(top: 20.0)),
// // // const Text('With remote mp4'),
// // Container(
// // // padding: const EdgeInsets.all(20),
// // child:
// // ),
// ],
// ),
// ))
)
: Container(
width: ScreenUtil().screenWidth,
height: ScreenUtil().screenHeight,
color: MyColours.color_000000,
child: SizedBox(
width: ScreenUtil().setWidth(80),
height: ScreenUtil().setWidth(80),
child: Center(
child: CircularProgressIndicator(
color: Colors.white,
),
)),
),
));
}
}
class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({required this.controller});
// static const List<Duration> _exampleCaptionOffsets = <Duration>[
// Duration(seconds: -10),
// Duration(seconds: -3),
// Duration(seconds: -1, milliseconds: -500),
// Duration(milliseconds: -250),
// Duration.zero,
// Duration(milliseconds: 250),
// Duration(seconds: 1, milliseconds: 500),
// Duration(seconds: 3),
// Duration(seconds: 10),
// ];
// static const List<double> _examplePlaybackRates = <double>[
// 0.25,
// 0.5,
// 1.0,
// 1.5,
// 2.0,
// 3.0,
// 5.0,
// 10.0,
// ];
final VideoPlayerController controller;
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
AnimatedSwitcher(
duration: const Duration(milliseconds: 50),
reverseDuration: const Duration(milliseconds: 200),
child: controller.value.isPlaying
? const SizedBox.shrink()
: const ColoredBox(
color: Colors.black26,
child: Center(
child: Icon(
Icons.play_arrow,
color: Colors.white,
size: 50,
semanticLabel: 'Play',
),
),
),
),
GestureDetector(
onTap: () {
controller.value.isPlaying ? controller.pause() : controller.play();
},
),
// Align(
// alignment: Alignment.topLeft,
// child: PopupMenuButton<Duration>(
// initialValue: controller.value.captionOffset,
// tooltip: 'Caption Offset',
// onSelected: (Duration delay) {
// controller.setCaptionOffset(delay);
// },
// itemBuilder: (BuildContext context) {
// return <PopupMenuItem<Duration>>[
// for (final Duration offsetDuration in _exampleCaptionOffsets)
// PopupMenuItem<Duration>(
// value: offsetDuration,
// child: Text('${offsetDuration.inMilliseconds}ms'),
// )
// ];
// },
// child: Padding(
// padding: const EdgeInsets.symmetric(
// // Using less vertical padding as the text is also longer
// // horizontally, so it feels like it would need more spacing
// // horizontally (matching the aspect ratio of the video).
// vertical: 12,
// horizontal: 16,
// ),
// child: Text('${controller.value.captionOffset.inMilliseconds}ms'),
// ),
// ),
// ),
// Align(
// alignment: Alignment.topRight,
// child: PopupMenuButton<double>(
// initialValue: controller.value.playbackSpeed,
// tooltip: 'Playback speed',
// onSelected: (double speed) {
// controller.setPlaybackSpeed(speed);
// },
// itemBuilder: (BuildContext context) {
// return <PopupMenuItem<double>>[
// for (final double speed in _examplePlaybackRates)
// PopupMenuItem<double>(
// value: speed,
// child: Text('${speed}x'),
// )
// ];
// },
// child: Padding(
// padding: const EdgeInsets.symmetric(
// // Using less vertical padding as the text is also longer
// // horizontally, so it feels like it would need more spacing
// // horizontally (matching the aspect ratio of the video).
// vertical: 12,
// horizontal: 16,
// ),
// child: Text('${controller.value.playbackSpeed}x'),
// ),
// ),
// ),
],
);
}
}