Reputation: 651
var audio = new Audio('data:audio/wav;base64,UklGRoABAABXQVZFZm10IBAAAAABAAEAiBUAAIgVAAABAAgAZGF0YVwBAACHlqa1xNLg7vv/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Tk1LSklHRkVEQ0JBQD8+Pj08PDs6Ojk5OTg4ODg3Nzc3Nzc3Nzc3Nzc3Nzg4ODg5OTk6Ojs7Ozw8PT4+P0BAQUJCQ0RFRUZHSElJSktMTU5OT1BRUlNUVVVWV1hZWltcXV1eX2BhYmNkZGVmZ2hpaWprbG1ubm9wcXFyc3R0dXZ3d3h5eXp6e3x8fX1+f3+AgIGBgoKCg4OEhISFhYWGhoaHh4eHh4iIiIiIiIiIiIiIiIiIiIiIiIiIiIeHh4eHhoaGhYWFhISEg4OCgoGBgIA=');
setInterval(function() {
audio.play();
}, 50);
This code works correctly in Chrome and Firefox, but in Safari there's a delay of over a second between each sound. I can't figure out why this would be, as far as I can tell there are no compatibility issues. I want to play sounds at a precise time and at a reasonably fast delay in a game that I'm making, how can I get this working?
Upvotes: 3
Views: 4172
Reputation: 2386
I have no idea why, but adding AudioContext removes the delay.
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioContext();
Found out by accident, works for me. Go figure.
Safari version 12.0 (14606.1.36.1.9).
Upvotes: 7