javascript - Web Audio API 演示在 iOS 上不起作用

标签 javascript ios iphone web-audio-api

我目前正在努力改编这个 web audio API demo对于我正在做的一个项目,但是当我在 iPhone 上测试时没有声音。它在 iPad 上运行良好。

我搜索了解决方案并找到了这个 thread在 StackOverflow 上使用以下答案之一的片段:

Safari on iOS 6 effectively starts with the Web Audio API muted. It will not unmute until you attempt to play a sound in a user input event (create a buffer source, connect it to destination, and call noteOn()). After this, it unmutes and audio plays unrestricted and as it ought to. This is an undocumented aspect of how the Web Audio API works on iOS 6 (Apple's doc is here, hopefully they update it with a mention of this soon!)

用户输入事件应该是播放按钮上的 onclick 事件,但更改为使用 noteOn() 而不是 start() 仍然无法解决问题。

更新:我也尝试过将播放按钮与 touchend 事件绑定(bind),但没有成功。

这是使用 noteOn() 的函数:

function playNote(buffer, pan, x, y, z, sendGain, mainGain, playbackRate, noteTime) {
    // Create the note
    var voice = context.createBufferSource();
    voice.buffer = buffer;
    voice.playbackRate.value = playbackRate;

    // Optionally, connect to a panner
    var finalNode;
    if (pan) {
        var panner = context.createPanner();
        panner.panningModel = "HRTF";
        panner.setPosition(x, y, z);
        voice.connect(panner);
        finalNode = panner;
    } else {
        finalNode = voice;
    }

    // Connect to dry mix
    var dryGainNode = context.createGain();
    dryGainNode.gain.value = mainGain * effectDryMix;
    finalNode.connect(dryGainNode);
    dryGainNode.connect(masterGainNode);

    // Connect to wet mix
    var wetGainNode = context.createGain();
    wetGainNode.gain.value = sendGain;
    finalNode.connect(wetGainNode);
    wetGainNode.connect(convolver);

    if (iOS) {        
        voice.noteOn(noteTime);    
    }
    else {
        voice.start(noteTime);
    }
}

如有任何建议,我们将不胜感激。谢谢。

最佳答案

我觉得自己很蠢。显然,如果您的 iPhone 处于振动模式,则不会播放声音。

关于javascript - Web Audio API 演示在 iOS 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46010483/

相关文章:

c# - 使用 Monotouch 从 Iphone 的 key 链访问客户端证书

iphone - 将 Controller 插入堆栈后,后退按钮未显示

iphone - 如何获取动态 JSON

ios - Swift 中的 16 位逻辑/计算机模拟

ios - 检测选定 UITabbarItem 上的重新制表符

javascript - 使用 jquery 插入后按钮操作不起作用

javascript - 按字母顺序对 JSON 响应对象进行排序

objective-c - 在突出显示/选择单元格时,在自定义 UITableViewCell 中为 UITextField 提供正确的文本颜色

asp.net - 如何隐藏窗口

没有jquery的javascript find()函数