javascript - HTML5 如何为 JavaScript 游戏替换 Internet Explorer 的 WebAudio API?

标签 javascript internet-explorer html5-audio web-audio-api soundmanager2

我是 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/

相关文章:

javascript - 使用 HapiJS 出现身份验证错误

javascript - Angular 分页,获取当前页码

IE 中的 JavaScript 错误

asp.net - 剪切文本在 Chrome 中有效,但在 IE9 中无效?

python - Google App Engine 为音频元素提供 MP3 服务需要内容范围 header

javascript - Cytoscape JS 和 Angular8 的工具提示

javascript - 从 json 对象填充下拉列表时出错

jQueryUI 工具提示 : Issues with IE select boxes

firefox - 为什么 Firefox 不支持 <audio> 中的 MP3 文件格式

html - 为什么只有按下提交按钮时,网络主机所播放的html音频才会播放