0

I have an issue with Safari desktop. This snippet of code works even on the mobile version of Safari just not on the desktop version (12.1).

js

var targetBeep = "targetBeep";
var atmos = "atmos";

createjs.Sound.registerSound("targetBeep.mp3", targetBeep);
createjs.Sound.registerSound("25372639_dark-tension-atmosphere_by_umcsound_preview.mp3", atmos);

$( ".play" ).css({'cursor': 'pointer'}).click(function() {
  setTimeout(function () {
  createjs.Sound.play(atmos);
  }, 2000);
});

HTML

<div class="play">
  play
</div>

<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src="https://code.createjs.com/1.0.0/createjs.min.js"></script>

Is it a problem with the code or is it Safari desktop? If its Safari what can I do to resolve this

var atmos = "atmos";

createjs.Sound.registerSound("https://upload.wikimedia.org/wikipedia/commons/1/12/03may2020-tobefree.mp3", atmos);

$(".play").css({
  'cursor': 'pointer'
}).click(function() {
  setTimeout(function() {
    createjs.Sound.play(atmos);
  }, 2000);
});
<div class="play">
  play
</div>

<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src="https://code.createjs.com/1.0.0/createjs.min.js"></script>
ziggelflex
  • 23
  • 4
  • _"I have an issue with Safari desktop"_... you're not alone. Are there any errors reported in the dev tools console? – Phil Jan 17 '22 at 23:31
  • I don't think so, I have added to the log after its supposed to play and it shows the message so its running just not working – ziggelflex Jan 17 '22 at 23:38
  • I have amended the post – ziggelflex Jan 17 '22 at 23:54
  • 1
    I added a runnable snippet to your question and confirmed it doesn't work for me either, Safari 15.1. Works fine in Chrome and Firefox – Phil Jan 18 '22 at 00:05
  • I would really like to use jquery for clickable assets. I have tried doing it vanilla and it works but it isn't what I want. Thanks for the snippet – ziggelflex Jan 18 '22 at 00:07
  • Have you tried without the `setTimeout`? There may be some media control restrictions coming in to play. If it still doesn't work, I'd try raising a bug report with SoundJS – Phil Jan 18 '22 at 01:04
  • You can simply add `createjs.Sound.play(atmos).stop();` in the `click()` handler (outside of the setTimeout). – Kaiido Jan 18 '22 at 05:26

0 Answers0