I like to add audio panning effect to Youtube.
But I found web audio api works in Chrome but not in Safari (v.13.1 on MacOS 10.15.4)
Steps to reproduce:
- Open Youtube Video in Safari
- Open the dev console and paste the following code
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);
};
- Click the Pan button
It should pan the audio to the left. But it didn't work in Safari.
The action is triggered by user click and it doesn't violate the cross-origin restriction.
Did I miss anything?