-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvideoplayer.html
131 lines (125 loc) · 3.35 KB
/
videoplayer.html
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
<m-group sx="0.4" sy="0.4" ry="-90">
<m-video
y="7"
width="25"
rx="0"
ry="0"
start-time="0"
loop="true"
src="https://public.mml.io/charge.mp4"
>
<m-label
onclick="restart(event.currentTarget.parentNode)"
content="restart"
x="10"
y="-6"
font-size="100"
width="4.5"
alignment="center"
height="1.5"
color="#cccccc"
></m-label>
<m-label
onclick="pause(event.currentTarget.parentNode)"
content="pause"
x="-10"
y="-6"
font-size="100"
width="4.5"
alignment="center"
height="1.5"
color="#cccccc"
></m-label>
<m-label
onclick="unpause(event.currentTarget.parentNode)"
content="unpause"
x="-5"
y="-6"
font-size="100"
width="4.5"
alignment="center"
height="1.5"
color="#cccccc"
></m-label>
<m-label
onclick="resume(event.currentTarget.parentNode)"
content="resume"
x="5"
y="-6"
font-size="100"
width="4.5"
alignment="center"
height="1.5"
color="#cccccc"
></m-label>
<m-label
onclick="toggleEnabled(event.currentTarget.parentNode)"
content="enable"
x="0"
y="-6"
font-size="100"
width="4.5"
alignment="center"
height="1.5"
color="#cccccc"
></m-label>
<m-label
class="attributes-label"
content="attrs:"
x="0"
y="6.5"
padding="20"
font-size="50"
width="25"
alignment="center"
height="2"
color="green"
font-color="white"
></m-label>
</m-video>
</m-group>
<script>
function updateAttributesLabel(videoTag) {
const attributes = [];
for (const attr of videoTag.getAttributeNames()) {
const val = videoTag.getAttribute(attr);
attributes.push(`${attr}="${val}"`);
}
const attributesLabel = videoTag.querySelector(".attributes-label");
if (attributesLabel) {
attributesLabel.setAttribute("content", `<m-video ${attributes.join(" ")}></m-video>`);
}
}
function restart(videoTag) {
videoTag.setAttribute("pause-time", document.timeline.currentTime);
videoTag.setAttribute("start-time", document.timeline.currentTime);
videoTag.removeAttribute("pause-time");
updateAttributesLabel(videoTag);
}
function toggleEnabled(videoTag) {
const enabled = videoTag.getAttribute("enabled") !== "false";
videoTag.setAttribute("enabled", (!enabled).toString());
updateAttributesLabel(videoTag);
}
function pause(videoTag) {
videoTag.setAttribute("pause-time", document.timeline.currentTime);
updateAttributesLabel(videoTag);
}
function unpause(videoTag) {
videoTag.removeAttribute("pause-time");
updateAttributesLabel(videoTag);
}
function resume(videoTag) {
if (!videoTag.hasAttribute("pause-time")) return;
const startTime = parseFloat(videoTag.getAttribute("start-time")) || 0;
const pauseTime = parseFloat(videoTag.getAttribute("pause-time")) || 0;
const playedDuration = pauseTime - startTime;
const newStartTime = document.timeline.currentTime - playedDuration;
videoTag.removeAttribute("pause-time");
videoTag.setAttribute("start-time", newStartTime);
updateAttributesLabel(videoTag);
}
for (const video of document.querySelectorAll("m-video")) {
updateAttributesLabel(video);
}
</script>