Audio Source Working
HTML
<input type="button" id="play" value = "PLAY">
JavaScript
var context = new AudioContext();
//var myBufferTest = null;
//var url = 'http://thelab.thingsinjars.com/web-audio-tutorial/hello.mp3';
var button = document.getElementById('play');
//setting up a loader object
function Sound(source){
this.counter = 0;
var that = this;
that.source = source;
that.buffer = null;
that.isLoaded = false;
var request = new XMLHttpRequest();
request.open('GET', source , true);
request.responseType = "arraybuffer";
request.onload = function(){
context.decodeAudioData(request.response, function(buffer){
that.buffer = buffer;
that.isLoaded = true;
that.barrier();
});
};
request.send();
}
Sound.prototype.play = function(){
this.barrier();
};
Sound.prototype.barrier = function(){
this.counter++;
if(this.counter >= 2){
var Seda = context.createBufferSource();
Seda.buffer = this.buffer;
Seda.connect(context.destination);
Seda.start(0);
}
};
test = new Sound('https://s3.eu-central-1.amazonaws.com/mph-music/upbeat-2-1.mp3');
button.addEventListener('click', function(){
test.play();
});
test.play();