system-bus-radio/In Javascript/airgap.js

29 lines
845 B
JavaScript
Raw Normal View History

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
var logs = document.getElementById('logs'); // Define log element
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
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;
window.logs.value += data;
};
2016-03-04 18:41:03 +01:00
2016-11-27 06:51:16 +01:00
// Send song data to player
var song = document.getElementById("tones").innerHTML;
player.postMessage(song);
}
2016-03-04 18:41:03 +01:00
}
2016-11-27 06:51:16 +01:00
function end() { // Stops the Web Worker
player.terminate();
2016-03-04 18:41:03 +01:00
}
function pause(time) {
window.logs.value += "\nPaused / " + time*.001 + " seconds";
var dt = new Date();
while ((new Date()) - dt <= time) { /* Do nothing */ }
}