mirror of
https://github.com/danog/system-bus-radio.git
synced 2024-12-02 10:07:46 +01:00
28 lines
800 B
JavaScript
28 lines
800 B
JavaScript
var player; // Define "player" var to make my code linter happy
|
|
|
|
function start() { // Start Web Worker & send song data to player
|
|
var logs = document.getElementById('progress'); // Define log element
|
|
window.logs = logs; // Make variable Global
|
|
window.logs.value = "";
|
|
|
|
// Create Web Worker if it doesn't already exist
|
|
if (window.Worker && typeof(player) == "undefined") {
|
|
var player = new Worker("worker.js");
|
|
window.player = player; // Make variable Global
|
|
player.onmessage = function(event) {
|
|
var data = event.data;
|
|
console.log(data)
|
|
window.logs.value += "x\n";
|
|
};
|
|
|
|
// Send song data to player
|
|
var song = document.getElementById("tune").innerHTML;
|
|
player.postMessage(song);
|
|
}
|
|
}
|
|
|
|
function end() { // Stops the Web Worker
|
|
window.logs.value = "";
|
|
player.terminate();
|
|
}
|