-
Notifications
You must be signed in to change notification settings - Fork 186
/
main.dart
132 lines (114 loc) · 4.08 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
import 'package:appinio_video_player/appinio_video_player.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const CupertinoApp(
debugShowCheckedModeBanner: false,
theme: CupertinoThemeData(
brightness: Brightness.light,
),
title: 'Appinio Video Player Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late CachedVideoPlayerController _videoPlayerController,
_videoPlayerController2,
_videoPlayerController3;
late CustomVideoPlayerController _customVideoPlayerController;
late CustomVideoPlayerWebController _customVideoPlayerWebController;
final CustomVideoPlayerSettings _customVideoPlayerSettings =
const CustomVideoPlayerSettings(showSeekButtons: true);
final CustomVideoPlayerWebSettings _customVideoPlayerWebSettings =
CustomVideoPlayerWebSettings(
src: longVideo,
);
@override
void initState() {
super.initState();
_videoPlayerController = CachedVideoPlayerController.network(
longVideo,
)..initialize().then((value) => setState(() {}));
_videoPlayerController2 = CachedVideoPlayerController.network(video240);
_videoPlayerController3 = CachedVideoPlayerController.network(video480);
_customVideoPlayerController = CustomVideoPlayerController(
context: context,
videoPlayerController: _videoPlayerController,
customVideoPlayerSettings: _customVideoPlayerSettings,
additionalVideoSources: {
"240p": _videoPlayerController2,
"480p": _videoPlayerController3,
"720p": _videoPlayerController,
},
);
_customVideoPlayerWebController = CustomVideoPlayerWebController(
webVideoPlayerSettings: _customVideoPlayerWebSettings,
);
}
@override
void dispose() {
_customVideoPlayerController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text("Appinio Video Player"),
),
child: SafeArea(
child: ListView(
physics: const NeverScrollableScrollPhysics(),
children: [
kIsWeb
? Expanded(
child: CustomVideoPlayerWeb(
customVideoPlayerWebController:
_customVideoPlayerWebController,
),
)
: CustomVideoPlayer(
customVideoPlayerController: _customVideoPlayerController,
),
CupertinoButton(
child: const Text("Play Fullscreen"),
onPressed: () {
if (kIsWeb) {
_customVideoPlayerWebController.setFullscreen(true);
_customVideoPlayerWebController.play();
} else {
_customVideoPlayerController.setFullscreen(true);
_customVideoPlayerController.videoPlayerController.play();
}
},
),
],
),
),
);
}
}
String videoUrlLandscape =
"https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4";
String videoUrlPortrait =
'https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4';
String longVideo =
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
String video720 =
"https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_10mb.mp4";
String video480 =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4";
String video240 =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";