Created
August 20, 2015 03:22
-
-
Save Noitidart/623504c57892eda24d74 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-playSound - Trying to use Audio API to play sound.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function audioContextCheck() { | |
if (typeof Services.appShell.hiddenDOMWindow.AudioContext !== 'undefined') { | |
return new Services.appShell.hiddenDOMWindow.AudioContext(); | |
} else if (typeof Services.appShell.hiddenDOMWindow.mozAudioContext !== 'undefined') { | |
return new Services.appShell.hiddenDOMWindow.mozAudioContext(); | |
} else { | |
throw new Error('AudioContext not supported'); | |
} | |
} | |
var audioContext = audioContextCheck(); | |
var audioBuffer; | |
var getSound = new XMLHttpRequest(); | |
getSound.open('get', OS.Path.toFileURI(OS.Path.join(OS.Constants.Path.desktopDir, 'zirzir.mp3')), true); | |
getSound.responseType = 'arraybuffer'; | |
getSound.onload = function() { | |
audioContext.decodeAudioData(getSound.response, function(buffer) { | |
audioBuffer = buffer; | |
var playSound = audioContext.createBufferSource(); | |
playSound.buffer = audioBuffer; | |
playSound.connect(audioContext.destination); | |
playSound.start(audioContext.currentTime); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1
zirzir.mp3