Safari-createMediaElementSource不起作用?

问题描述 投票:0回答:1

我喜欢向YouTube添加音频平移效果。

但是我发现Web音频api在Chrome中有效,但在Safari中不起作用(在MacOS 10.15.4上为v3.1.1)

复制步骤:

  1. 在Safari中打开Youtube视频
  2. 打开开发者控制台并粘贴以下代码
    var button = document.createElement("button");
    button.innerHTML = "Pan";
    button.style.position = "fixed"
    button.style.backgroundColor = "#0C9"
    button.style.bottom = "20px"
    button.style.right = "20px"
    button.style.fontSize = "24px"

    document.body.appendChild(button);

    let audioCtx = new (window.AudioContext || window.webkitAudioContext);
    const videoElement = document.querySelector('video');

    button.onclick = () => {
        console.log("== onclick ==")
        const source = audioCtx.createMediaElementSource(videoElement);
        var panner = audioCtx.createPanner();
        panner.panningModel = 'equalpower';
        panner.setPosition(-1, 0, 0);

        source.connect(panner);
        panner.connect(audioCtx.destination);
    };
  1. 单击平移按钮

它应该将音频平移到左侧。但是它在Safari中不起作用。

动作是triggered by user click,并且没有违反cross-origin restriction

我有什么想念吗?

safari web-audio-api
1个回答
0
投票

简而言之:

createMediaElementSource不适用于Safari中的流媒体源。

根据此线程Possible to analyze streaming audio from Icecast using Web Audio API and createMediaElementSource?

我测试过:

  • 案例1:带有音频问题的流源=>静音

  • 情况2:具有正确cors的流式源=>播放声音,但没有来自源节点的数据。

我还将静态文件作为源案例进行了测试。 Safari正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.