/
main.dart
153 lines (144 loc) · 4.63 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
import 'package:flutter/material.dart';
import 'package:drm_video/drm_video.dart';
import 'package:drm_video/video_controller.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
VideoController _videoController;
String dashUrl = "https://storage.googleapis.com/wvmedia/cenc/h264/tears/tears.mpd";
String licenseUrl = "https://proxy.staging.widevine.com/proxy";
@override
void dispose() {
_videoController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
AspectRatio(
aspectRatio: _videoController?.value?.aspectRatio ?? 16 / 9,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Container(
child: DrmVideoPlayer(
videoUrl: dashUrl,
autoPlay: false,
drmLicenseUrl: licenseUrl,
onVideoControls: (VideoController controller) {
print("onVideoControls $controller");
_videoController = controller;
_videoController.addListener(() {
setState(() {});
});
setState(() {});
},
),
),
if (_videoController != null)
_ControlsOverlay(controller: _videoController),
],
),
),
if (_videoController != null)
VideoProgressIndicator(_videoController, allowScrubbing: true),
if (_videoController != null)
Text("text ${_videoController.value.position}"),
if (_videoController != null)
Text("text ${_videoController.value.duration}"),
Text("text ${_videoController == null}"),
],
),
),
),
);
}
}
class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({Key key, this.controller}) : super(key: key);
static const _examplePlaybackRates = [
0.25,
0.5,
1.0,
1.5,
2.0,
3.0,
5.0,
10.0,
];
final VideoController controller;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: controller?.value?.aspectRatio ?? 16 / 9,
child: Stack(
children: <Widget>[
AnimatedSwitcher(
duration: Duration(milliseconds: 50),
reverseDuration: Duration(milliseconds: 200),
child: controller.value.isPlaying
? SizedBox.shrink()
: Container(
color: Colors.black26,
child: Center(
child: Icon(
Icons.play_arrow,
color: Colors.white,
size: 100.0,
),
),
),
),
GestureDetector(
onTap: () {
controller.value.isPlaying
? controller.pause()
: controller.play();
},
),
Align(
alignment: Alignment.topRight,
child: PopupMenuButton<double>(
initialValue: controller.value.playbackSpeed,
tooltip: 'Playback speed',
onSelected: (speed) {
controller.setPlaybackSpeed(speed);
},
itemBuilder: (context) {
return [
for (final speed in _examplePlaybackRates)
PopupMenuItem(
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'),
),
),
),
],
),
);
}
}