Can anyone tell me a simple and reliable test (in javascript/jquery) for whether the current browser supports the Web Audio Api? Needs to work on mobile.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
If I understand you correctly...
var context;
window.addEventListener('load', init, false);
function init() {
try {
// Fix up for prefixing
window.AudioContext = window.AudioContext||window.webkitAudioContext;
context = new AudioContext();
}
catch(e) {
alert('Web Audio API is not supported in this browser');
}
}
That's taken directly from here (article by Boris Smus).
Here's a way to initialize a web audio context taking into account future implementations of the Web Audio API which don't exist yet. Taken from here.
var contextClass = (window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext);
if (contextClass) {
// Web Audio API is available.
var context = new contextClass();
} else {
// Web Audio API is not available. Ask the user to use a supported browser.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With