2016-11-27 06:51:16 +01:00
|
|
|
var player; // Define "player" var to make my code linter happy
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
function start() { // Start Web Worker & send song data to player
|
2017-11-12 02:16:54 +01:00
|
|
|
var logs = document.getElementById('progress'); // Define log element
|
|
|
|
window.logs = logs; // Make variable Global
|
|
|
|
window.logs.value = "";
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
// Create Web Worker if it doesn't already exist
|
2016-11-27 06:13:23 +01:00
|
|
|
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;
|
2017-11-12 02:16:54 +01:00
|
|
|
console.log(data)
|
|
|
|
window.logs.value += "x\n";
|
2016-11-27 06:13:23 +01:00
|
|
|
};
|
2016-03-04 18:41:03 +01:00
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
// Send song data to player
|
2017-11-12 02:16:54 +01:00
|
|
|
var song = document.getElementById("tune").innerHTML;
|
2016-11-27 06:13:23 +01:00
|
|
|
player.postMessage(song);
|
2016-03-08 05:58:24 +01:00
|
|
|
}
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|
|
|
|
|
2016-11-27 06:51:16 +01:00
|
|
|
function end() { // Stops the Web Worker
|
2017-11-12 02:16:54 +01:00
|
|
|
window.logs.value = "";
|
2016-11-27 06:13:23 +01:00
|
|
|
player.terminate();
|
2016-03-04 18:41:03 +01:00
|
|
|
}
|