if ( typeof window.Audio !== 'undefined' ) {
// create new Audio Node
var canHasSound = new Audio();
// set source file, then load
canHasSound.src = "My_Amazing_Tunes.mp3";
canHasSound.load();
//...
// PLAY!!!!
canHasSound.play();
}
...
// set source file, then load
canHasSound.src = "My_Amazing_Tunes.mp3";
canHasSound.autobuffer = true;
canHasSound.preload = 'auto';
canHasSound.load();
window.addEventListener( 'touchstart' , _initialPlay , false );
window.addEventListener( 'play' , _focePause , false );
...
var context = new AudioContext();
function playSound( buffer ) {
// creates a sound source
var source = context.createBufferSource();
// tell the source which sound to play
source.buffer = buffer;
// connect the source to the context's destination (the speakers)
source.connect(context.destination);
// play the source now
source.start(0);
}
IOS and Android ( Chrome ) requires User Input / Action
window.addEventListener( 'touchstart' , _initialPlay , false );
window.addEventListener( 'play' , _focePause , false );
Latency is a measure of time delay experienced in a system.
// request sent to server with timestamp and returned
// with original time and server timestamp
responseReceived = new Date.getTime();
serverTime = objTimes.server;
original = objTimes.original;
// check time taken for entire request
latency = Math.round( ( responseReceived - original ) * 0.5 );
responseReceived -= latency;
To Cater for the various devices and the latency on each, using WebSockets we push the time required and factor in latency
// add the latency to the start time for the given track
_startTime = data.startTime + getMean( arrLateny )