AudioContext()在某些手机上不存在? [英] AudioContext() doesn't exist on some phones?

查看:355
本文介绍了AudioContext()在某些手机上不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Samsung Galaxy SII 4G上使用最新版本的Chrome(34.0.1847.114)中的AudioContext(),但由于某种原因AudioContext()不存在,webkitAudioContext也不存在。完全相同的代码在Nexus 5和旧款手机(如Galaxy Nexus)上功能完好,但不支持SII。某些设备是否支持HTML5音频?如果不是,任何人都可以解释为什么,或者指向我关于AudioContext支持的一些文档?



我正在使用的准确代码:

  window.AudioContext = window.AudioContext || window.webkitAudioContext; 
context = new AudioContext();

再一次,这在其他Android手机上效果很好。在S2上,我得到了Uncaught TypeError:undefined不是函数。

解决方案

Webaudio API仍然是一个工作草案。在这里查看支持列表

显然不是所有的Android设备都准备好了......但是。有关示例,请参见
与在这些新的(令人兴奋的)功能中,您需要在设备上使用它们之前测试支持:

  var contextClass =(window.AudioContext || 
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext);
if(contextClass){
// Web Audio API可用。
var context = new contextClass();
} else {
// Web Audio API不可用。后退
}

参考资料


I'm attempting to use AudioContext() in the latest version of Chrome (34.0.1847.114) on a Samsung Galaxy SII 4G, but for some reason AudioContext() does not exist, nor does webkitAudioContext. The exact same code functions perfectly fine on a Nexus 5 and an older phone like a Galaxy Nexus, but not the SII. Is HTML5 audio not supported on some devices? If not can anyone explain why or point me to some documentation about AudioContext support?

Exact code I'm using:

window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();

Again, this works perfectly fine on other Android phones. On the S2 I get "Uncaught TypeError: undefined is not a function".

解决方案

Webaudio API is still a working draft. See here for a support list.

Apparently not all Android devices are ready for it ... yet. See here for an example. As with any of those new (exciting) features you need to test support before using them on a device:

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. Fallback
}

Reference

这篇关于AudioContext()在某些手机上不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆