-
Notifications
You must be signed in to change notification settings - Fork 4
/
worker-player.js
52 lines (49 loc) · 1.61 KB
/
worker-player.js
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
import Renderer from './src/renderer/web-gl';
import WorkerPlayer from './src/worker/player';
import wasmBinary from './src/wasm-binary';
import videoData from './video-data';
function initCanvas(videoData) {
const wrapHeight = window.innerHeight;
const wrapWidth = Math.floor(window.innerHeight / videoData.height * videoData.width);
const wrap = {
height: wrapHeight,
width: wrapWidth,
top: 0,
left: -(wrapWidth - window.innerWidth) / 2 | 0,
};
const wrapDom = document.querySelector('.canvas-wrap');
wrapDom.style.width = wrap.width + 'px';
wrapDom.style.height = wrap.height + 'px';
wrapDom.style.top = wrap.top + 'px';
wrapDom.style.left = wrap.left + 'px';
const canvas = document.querySelector('#video-content');
canvas.width = wrapWidth;
canvas.height = wrapHeight;
return canvas;
}
window.addEventListener('load', async () => {
const canvas = initCanvas(videoData);
const worker = new Worker('./worker-proxy.js');
const renderer = new Renderer({ canvas });
const player = new WorkerPlayer({
worker,
renderer,
url: videoData.url,
loop: true,
autoplay: true,
progressive: true,
wasmBinary,
chunkSize: 1 * 1024 * 1024,
videoBufferSize: 1 * 1024 * 1024,
disableWebAssembly: true,
onSourceEstablished() {
console.log('onSourceEstablished');
player.play();
},
onWorkerPlayerInit() {
console.log('onWorkerPlayerInit');
},
});
console.log(player);
window.player = player;
}, false);