-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.js
More file actions
42 lines (34 loc) · 1.15 KB
/
b.js
File metadata and controls
42 lines (34 loc) · 1.15 KB
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
(function () {
const ME = "B";
if (!window.SharedWorker) {
console.log("window.SharedWorker not available");
return;
}
const audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'audio.mp3');
audioElement.setAttribute('loop', 'loop');
audioElement.setAttribute('controls', 'controls');
// audioElement.load() // default
document.body.appendChild(audioElement);
// audioElement.setAttribute('autoplay', 'autoplay');
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
const sharedWorker = new SharedWorker("sharedworker.js", "audio");
sharedWorker.port.onmessage = function(event) {
const messageObject = event.data
console.log("received", messageObject);
if (messageObject.hasOwnProperty("play")) {
if (messageObject.play) {
audioElement.play();
} else {
audioElement.pause();
}
}
};
sharedWorker.port.start();
sharedWorker.port.postMessage({
from: ME,
start: true
});
}());