问题
I'm new with audio in html. I found some nice examples for little javascript games. Want I try to load the games in Internet Explorer, I got : "Web api audio is not supported in this browser".
I found this site : http://caniuse.com/#feat=audio-api and look like Internet Explorer doesn't support it.
I found also SoundManager 2 that seem to work on all browsers.
My question, is there is a way to detect if the browser support WebApiAudio and offering a fallback if is not supported ?
I want to be able to offer the same functionality on all differents browsers, but I have no idea how to do that at this point.
One nice feature is able to play multiple sounds in the same time with ajustable volume sound (like explosions).
I want to create a helloworld that I could run on PC, Mac, Android and Ipad. Is it possible ?
thanks a lot for my multiple questions.
I check this demo :http://www.cocos2d-x.org/wiki/MoonWarriors_-_Cocos2d-JS_Showcase the sound works fine in Firefox, but in Internet Explorer there is only music, not sound effects
回答1:
My question, is there is a way to detect if the browser support WebApiAudio and offering a fallback if is not supported ?
"use strict"
function audioContextCheck() {
if (typeof AudioContext !== "undefined") {
return new AudioContext();
} else if (typeof webkitAudioContext !== "undefined") {
return new webkitAudioContext();
} else if (typeof mozAudioContext !== "undefined") {
return new mozAudioContext();
} else {
// Do stuff with soundmanager or something else if Web Audio API is not supported
}
}
var audioContext = audioContextCheck();
来源:https://stackoverflow.com/questions/27708341/html5-how-to-replace-webaudio-api-for-internet-explorer-for-javascript-games