-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
71 lines (54 loc) · 1.83 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
class LibOpenmptNode extends AudioWorkletNode {
constructor(ctx, options) {
const defaultOptions = {
numberOfInputs: 0,
numberOfOutputs: 1,
outputChannelCount: [2]
};
Object.assign(defaultOptions, options);
super(ctx, 'libopenmpt-processor', defaultOptions);
}
setPosition(pos) {
this.port.postMessage({setPosition: 0});
}
stop() {
this.port.postMessage({songData: new ArrayBuffer(0)});
}
}
let node;
let ctx;
async function init() {
ctx = new AudioContext();
await ctx.audioWorklet.addModule('mpt-worklet.js');
node = new LibOpenmptNode(ctx);
node.connect(ctx.destination);
node.port.onmessage = (msg) => {
if (msg.data.position != null) {
document.getElementById('position').innerText = Math.round(msg.data.position);
}
};
setInterval(() => {
node.port.postMessage({getPosition: 1});
}, 1000);
}
async function play() {
await initPromise;
ctx.resume();
const response = await fetch("milksun.it");
const butterfl = await response.arrayBuffer();
node.port.postMessage({songData: butterfl, setRepeatCount: -1});
}
const initPromise = init();
</script>
<button onclick="play()">Play</button>
<button onclick="node.setPosition(0)">Restart</button>
<button onclick="node.stop();">Stop</button>
<p>Position: <span id="position"></span></p>
</body>
</html>