-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
224 lines (202 loc) · 6.73 KB
/
main.dart
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
import 'package:fl_video/fl_video.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
theme: ThemeData.light(useMaterial3: true),
darkTheme: ThemeData.dark(useMaterial3: true),
debugShowCheckedModeBanner: false,
title: 'FlVideo',
home: const _HomePage()));
}
class _HomePage extends StatefulWidget {
const _HomePage();
@override
State<_HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<_HomePage>
with SingleTickerProviderStateMixin {
late TabController controller;
final controls = [
const _MaterialControlsVideoPlayer(),
const _CupertinoControlsVideoPlayer()
];
@override
void initState() {
super.initState();
controller = TabController(length: 2, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Fl Video Player')),
body: SafeArea(
bottom: true,
child: Column(children: [
Expanded(
child: TabBarView(
physics: const NeverScrollableScrollPhysics(),
controller: controller,
children: controls)),
const SizedBox(height: 40),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
ElevatedText(
onPressed: () {
controller.animateTo(0);
},
text: "MaterialControls"),
ElevatedText(
onPressed: () {
controller.animateTo(1);
},
text: 'CupertinoControls')
]),
const SizedBox(height: 40),
]),
));
}
}
class _CupertinoControlsVideoPlayer extends StatefulWidget {
const _CupertinoControlsVideoPlayer();
@override
State<_CupertinoControlsVideoPlayer> createState() =>
_CupertinoControlsVideoPlayerState();
}
class _CupertinoControlsVideoPlayerState
extends State<_CupertinoControlsVideoPlayer> {
late FlVideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = FlVideoPlayerController(
videoPlayerController: VideoPlayerController.asset('assets/h.mp4'),
autoPlay: true,
looping: true,
overlay: const IgnorePointer(
child: Center(
child: Text('overlay',
style: TextStyle(color: Colors.lightBlue, fontSize: 20)))),
placeholder: const Center(
child: Text('placeholder',
style: TextStyle(color: Colors.red, fontSize: 20))),
controls: CupertinoControls(
hideDuration: const Duration(seconds: 5),
enableSpeed: true,
enableSkip: true,
enableSubtitle: true,
enableFullscreen: true,
enableVolume: true,
enablePlay: true,
enableBottomBar: true,
onTap: (FlVideoTapEvent event, FlVideoPlayerController controller) {
debugPrint(event.toString());
},
onDragProgress:
(FlVideoDragProgressEvent event, Duration duration) {
debugPrint('$event===$duration');
},
remainingBuilder: (String position) {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 6, 6, 6),
child: Text(position,
style: const TextStyle(fontSize: 16, color: Colors.red)));
},
positionBuilder: (String position) {
return Padding(
padding: const EdgeInsets.fromLTRB(6, 6, 0, 6),
child: Text(position,
style: const TextStyle(
fontSize: 16, color: Colors.lightBlue)));
}),
subtitle: Subtitles([
Subtitle(
index: 0,
start: Duration.zero,
end: const Duration(seconds: 10),
text: 'No.1 subtitle'),
Subtitle(
index: 0,
start: const Duration(seconds: 10),
end: const Duration(seconds: 20),
text: 'No.2 subtitle)'),
]));
}
@override
Widget build(BuildContext context) {
return FlVideoPlayer(controller: _controller);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
class _MaterialControlsVideoPlayer extends StatefulWidget {
const _MaterialControlsVideoPlayer();
@override
State<_MaterialControlsVideoPlayer> createState() =>
_MaterialControlsVideoPlayerState();
}
class _MaterialControlsVideoPlayerState
extends State<_MaterialControlsVideoPlayer> {
late FlVideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = FlVideoPlayerController(
videoPlayerController: VideoPlayerController.asset('assets/v.mp4'),
autoPlay: true,
looping: true,
overlay: const IgnorePointer(
child: Center(
child: Text('overlay',
style: TextStyle(color: Colors.lightBlue, fontSize: 20)))),
placeholder: const Center(
child: Text('placeholder',
style: TextStyle(color: Colors.red, fontSize: 20))),
controls: MaterialControls(
hideDuration: const Duration(seconds: 5),
enablePlay: true,
enableFullscreen: true,
enableSpeed: true,
enableVolume: true,
enableSubtitle: true,
enablePosition: true,
enableBottomBar: true,
onTap: (FlVideoTapEvent event, FlVideoPlayerController controller) {
debugPrint(event.toString());
},
onDragProgress:
(FlVideoDragProgressEvent event, Duration duration) {
debugPrint('$event===$duration');
}),
subtitle: Subtitles([
Subtitle(
index: 0,
start: Duration.zero,
end: const Duration(seconds: 10),
text: 'No.1 subtitle'),
Subtitle(
index: 0,
start: const Duration(seconds: 10),
end: const Duration(seconds: 20),
text: 'No.2 subtitle)'),
]));
}
@override
Widget build(BuildContext context) {
return FlVideoPlayer(controller: _controller);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
class ElevatedText extends StatelessWidget {
const ElevatedText({super.key, this.onPressed, required this.text});
final VoidCallback? onPressed;
final String text;
@override
Widget build(BuildContext context) =>
ElevatedButton(onPressed: onPressed, child: Text(text));
}