summaryrefslogtreecommitdiff
path: root/webaudio.js
diff options
context:
space:
mode:
Diffstat (limited to 'webaudio.js')
-rw-r--r--webaudio.js74
1 files changed, 0 insertions, 74 deletions
diff --git a/webaudio.js b/webaudio.js
deleted file mode 100644
index 71c1dc4..0000000
--- a/webaudio.js
+++ /dev/null
@@ -1,74 +0,0 @@
-//creating an audio context
-var context;
-var audioBuffer;
-window.addEventListener('load', init);
-
-function init()
-{
- try
- {
- window.AudioContext = window.AudioContext || window.webkitAudioContext;
- context=new AudioContext();
- }
- catch(e)
- {
- alert("Your browser doesn't support Web Audio API");
- }
- initAudio();
-}
-
-function initAudio(){
- console.log("audio ready");
- console.log("inside audio initialized callback");
- var url1 = "someurl"
- var url2 = "someotherurl"
- loadAndPlay(url1, function(){
- loadAndPlay(url2, function(){
- console.log("played both urls");
- });
- });
-
-
-}
-function loadAndPlay(url, callback) {
- var audioURL=url;
-
- //creating a new request
- var request = new XMLHttpRequest();
- request.open("GET",audioURL,true);
- request.responseType= 'arraybuffer';
- request.onload = function(){
- //take the audio from http request and decode it in an audio buffer
- context.decodeAudioData(request.response, function(buffer){
- audioBuffer = buffer;
- console.log(audioBuffer);
- if(audioBuffer){ // check here
- playSound(callback);
- }
- });
-
- };
-
- request.send();
-}
-
-//playing the audio file
-function playSound(callback) {
-
- //creating source node
- var source = context.createBufferSource();
- //passing in file
- source.buffer = audioBuffer;
- source.onended = function(){
- console.log("inside ended callback");
- console.log("ended");
- if (typeof(callback) != "undefined" ){
- callback();
- }
- }
- //start playing
- source.connect(context.destination); // added
- source.start(0);
- console.log('playing');
-
-}