mirror of
https://github.com/danog/system-bus-radio.git
synced 2024-12-03 15:17:45 +01:00
efc865ddd6
* 'master' of https://github.com/rocketinventor/system-bus-radio: Added comments to source code Implemented Web Workers Preperations for web using a worker moved var definition created var for window log fixed description meta Added a delay function and fixed time being *1000. improved link styling removed red outline around text box removed more unused CSS removed unused and unrelated CSS classes Improved formatting
29 lines
845 B
JavaScript
29 lines
845 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('logs'); // Define log element
|
|
|
|
// 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;
|
|
};
|
|
|
|
// Send song data to player
|
|
var song = document.getElementById("tones").innerHTML;
|
|
player.postMessage(song);
|
|
}
|
|
}
|
|
|
|
function end() { // Stops the Web Worker
|
|
player.terminate();
|
|
}
|
|
|
|
function pause(time) {
|
|
window.logs.value += "\nPaused / " + time*.001 + " seconds";
|
|
var dt = new Date();
|
|
while ((new Date()) - dt <= time) { /* Do nothing */ }
|
|
} |