-
Notifications
You must be signed in to change notification settings - Fork 4
/
player.html
119 lines (102 loc) · 2.57 KB
/
player.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
<!DOCTYPE html>
<html>
<head>
<title>[room_name] - video sync</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
overflow: hidden;
background: #000;
}
video {
width: 100vw;
height: 100vh;
}
canvas {
position: fixed; margin: auto;
top: 0; left: 0;
width: 256px;
height: 256px;
image-rendering: pixelated;
}
h2 {
position: fixed; margin: auto;
top: 256px; left: 0;
image-rendering: pixelated;
text-shadow: 0 0 32px #000;
color: #fff;
}
</style>
</head>
<body>
<video></video>
<script src="../socket.io.js"></script>
<script type="text/javascript">
var _GET = {};
window.location.search.substr(1).split("&").forEach(function(e, i) {
if (e=="") return;
let param = e.split("=");
_GET[param[0]] = param[1];
});
var socket = io("[namespace]");
var video = document.querySelector("video");
let actualPosition = 0;
setInterval(()=>{
if (!video.paused) actualPosition++;
if (Math.abs(video.currentTime-actualPosition)>2) { // seconds
console.log("out of sync");
socket.emit("getInfo");
}
}, 1000);
socket.on("getInfo", info=>{
console.log(info);
actualPosition = info.position;
if (video.src != info.src) video.src = info.src;
if (video.playing != info.playing) {
if (info.playing) {
video.play();
} else {
video.pause();
}
}
video.currentTime = info.position;
video.volume = info.volume;
});
socket.emit("getInfo");
if (_GET.dynamicLights) {
let canvas = document.createElement("canvas");
canvas.width = canvas.height = 3;
//document.body.appendChild(canvas);
//let debug = document.createElement("h2");
//document.body.appendChild(debug);
let ctx = canvas.getContext("2d");
function getColors() {
let colors = new Array();
[
ctx.getImageData(0,0,1,1).data,
ctx.getImageData(1,0,1,1).data,
ctx.getImageData(2,0,1,1).data,
ctx.getImageData(0,1,1,1).data,
ctx.getImageData(2,1,1,1).data,
ctx.getImageData(0,2,1,1).data,
ctx.getImageData(1,2,1,1).data,
ctx.getImageData(2,2,1,1).data,
].forEach(c=>{
colors = colors.concat([c[0],c[1],c[2]]);
});
//debug.textContent = colors.join(",");
return colors.join(",");
}
let renderWidth = 3;
if (_GET["3D"])renderWidth = 6;
if (window.qt) setInterval(()=>{
ctx.drawImage(video, 0, 0, renderWidth, 3);
EventBridge.emitWebEvent(getColors());
}, 1000/30);
}
</script>
</body>
</html>