最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What's causing this slowdelayed audio playback in Safari? - Stack Overflow

programmeradmin5浏览0评论
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 patibility 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?

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 patibility 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?

Share Improve this question asked Mar 6, 2014 at 6:37 SuffickSuffick 6611 gold badge6 silver badges16 bronze badges 1
  • Please check the solution here stackoverflow./a/58813681/2668045 – Arif Dewi Commented Nov 12, 2019 at 7:13
Add a ment  | 

1 Answer 1

Reset to default 7

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).

发布评论

评论列表(0)

  1. 暂无评论