I know that I need to create audio context after user interaction in Safari. However, the following code still didn't work.
HTML
<button onclick="play">Play</button>
Javascript
function play() {
var AudioContext = window.AudioContext || window.webkitAudioContext
var ctx = new AudioContext()
fetch('MP3_URL')
.then((response) => response.arrayBuffer())
.then((arrayBuffer) => ctx.decodeAudioData(arrayBuffer))
.then((audioBuffer) => {
var source = ctx.createBufferSource()
source.buffer = audioBuffer
source.connect(ctx.destination)
source.start(ctx.currentTime)
})
}
The same code working on Google Chrome but safari.