我是 html 音频的新手。我为小型 JavaScript 游戏找到了一些不错的示例。想要我尝试在 Internet Explorer 中加载游戏,我得到:“此浏览器不支持 Web api 音频”。
我找到了这个网站:http://caniuse.com/#feat=audio-api看起来 Internet Explorer 不支持它。
我还发现 SoundManager 2 似乎适用于所有浏览器。
我的问题是,是否有一种方法可以检测浏览器是否支持 WebApiAudio 并在不支持时提供回退?
我希望能够在所有不同的浏览器上提供相同的功能,但目前我不知道该怎么做。
一个不错的功能是能够同时播放多种声音,音量可调节(例如爆炸声)。
我想创建一个可以在 PC、Mac、Android 和 Ipad 上运行的 helloworld。可能吗?
非常感谢我的多个问题。
我检查了这个演示:http://www.cocos2d-x.org/wiki/MoonWarriors_-_Cocos2d-JS_Showcase在 Firefox 中声音正常,但在 Internet Explorer 中只有音乐,没有音效
最佳答案
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();
关于javascript - HTML5 如何为 JavaScript 游戏替换 Internet Explorer 的 WebAudio API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27708341/