javascript 无法让 Web Audio API 与 iOS 11 Safari 一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46249361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't get Web Audio API to work with iOS 11 Safari
提问by Artikash-Reinstate Monica
So iOS 11 Safari was supposed to add support for the Web Audio API, but it still doesn't seem to work with this javascript code:
所以 iOS 11 Safari 应该添加对 Web Audio API 的支持,但它似乎仍然不适用于以下 javascript 代码:
//called on page load
get_user_media = get_user_media || navigator.webkitGetUserMedia;
get_user_media = get_user_media || navigator.mozGetUserMedia;
get_user_media.call(navigator, { "audio": true }, use_stream, function () { });
function use_stream(stream){
var audio_context = new AudioContext();
var microphone = audio_context.createMediaStreamSource(stream);
window.source = microphone; // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=934512
var script_processor = audio_context.createScriptProcessor(1024, 1, 1);
script_processor.connect(audio_context.destination);
microphone.connect(script_processor);
//do more stuff which involves processing the data from user's microphone...
}
I copy pasted most of this code, so I only have a cursory understanding of it. I know that it's supposed to (and does, on other browsers) capture the user's microphone for further processing. I know that the code breaks on the var audio_context = new AudioContext();line (as in, no code after that is run), but don't have any error messages cause I don't have a mac which is required to debug iOS Safari (apple die already >_<) Anyone know what's going on and/or how to fix it?
我复制粘贴了大部分代码,所以我对它只有一个粗略的了解。我知道它应该(并且确实在其他浏览器上)捕获用户的麦克风以进行进一步处理。我知道代码断线了var audio_context = new AudioContext();(例如,在运行之后没有代码),但没有任何错误消息,因为我没有调试 iOS Safari 所需的 mac(苹果已经死了 >_ <) 任何人都知道发生了什么和/或如何解决它?
e: forgot to mention that I looked it up and apparently I need the keyword "webkit" before using Web Audio API in Safari, but making it var audio_context = new webkitAudioContext();doesn't work either
e:忘了说我查过了,显然在 Safari 中使用 Web Audio API 之前我需要关键字“webkit”,但是让它var audio_context = new webkitAudioContext();也不起作用
回答by Nathan Friedly
@TomW was on the right track - basically the webkitAudioContextis suspended unless it's created in direct response to the user's tap (before you get the stream).
@TomW 走在正确的轨道上 - 基本上webkitAudioContext是暂停,除非它是直接响应用户的点击而创建的(在您获得流之前)。
See my answer at https://stackoverflow.com/a/46534088/933879for more details and a working example.
有关更多详细信息和工作示例,请参阅我在https://stackoverflow.com/a/46534088/933879 上的回答。
回答by Kerry Davis
Nothing works on mobile save to home screen apps. I issued a bug report to Apple developer. Got a response that it was a duplicate ( which means they know..no clue if or when they will actually fix it).
移动保存到主屏幕应用程序没有任何效果。我向 Apple 开发人员发布了错误报告。得到了一个重复的回应(这意味着他们知道......不知道他们是否或何时会真正修复它)。

