【问题标题】:Simple way to test if the browser supports the Web Audio Api?测试浏览器是否支持 Web Audio Api 的简单方法?
【发布时间】:2016-04-25 03:48:46
【问题描述】:

谁能告诉我当前浏览器是否支持 Web Audio Api 的简单可靠的测试(在 javascript/jquery 中)?需要在移动设备上工作。

https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

【问题讨论】:

  • "AudioContext" in window?

标签: javascript jquery html browser web-audio-api


【解决方案1】:

这是一种初始化网络音频上下文的方法,同时考虑到未来尚不存在的网络音频 API 实现。取自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.
}

【讨论】:

  • 谢谢@thanksd,我会将其添加为替代方法,并与我们的网络音频专家讨论。
【解决方案2】:

如果我理解正确的话......

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');
  }
}

直接取自hereBoris Smus 的文章)。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-04-05
  • 2011-11-26
  • 2014-02-01
  • 1970-01-01
  • 2014-10-05
  • 2011-12-12
  • 2011-09-07
  • 1970-01-01
相关资源
最近更新 更多