AudioContext() doesn't exist on some phones?

限于喜欢 提交于 2019-12-06 03:25:25

问题


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".


回答1:


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




回答2:


It will depend what browser you are using. Web Audio is not supported in Android Native browser, but is supported in the latest Chrome which is the default browser on newer devices.

I work on SoundJS, which can let you build audio that will work everywhere if that is something you need.

Hope that helps.



来源:https://stackoverflow.com/questions/22977033/audiocontext-doesnt-exist-on-some-phones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!