SoundJS: Safari Never Auto-Play setting causes long delay ending in `fileerror` with no information.

Issue Details

  • Version used: 1.0.0

  • Describe whats happening: If desktop Safari is set to Never Auto-Play, after registering a sound, there is a several second delay, and then a fileerror event. The event doesn’t contain any info to determine that this setting was the cause.

Example

<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Sound JS Test</title>
    <script src="https://code.createjs.com/1.0.0/soundjs.min.js"></script>
  </head>

  <body onload="setup()">
    <script>
      function setup() {
        console.log("setup");
        createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
      }

      function playSound() {
        console.log("playSound");
        
        createjs.Sound.on("fileload", function (result) {
          console.log("fileload", result);
          createjs.Sound.play("tone");
        });
        
        createjs.Sound.on("fileerror", function (error) {
          console.log("fileerror", error);
        });
        
        createjs.Sound.registerSound("audio/tone.mp3", "tone");
      }
    </script>

    <button onclick="playSound()">Play Sound</button>
  </body>
</html>

Resulting logs:

[Log] setup (sound-js, line 13)
[Log] playSound (sound-js, line 18)
[Log] fileerror (sound-js, line 24)

Event
  bubbles: false
  cancelable: false
  currentTarget: function()
  data: 100
  defaultPrevented: false
  eventPhase: 2
  id: "tone"
  immediatePropagationStopped: false
  propagationStopped: false
  removed: false
  sprite: undefined
  src: "audio/tone.mp3" 
  target: function()
  timeStamp: 1613432337722 
  type: "fileerror"
  Event Prototype
  • OS & Browser version Safari Version 14.0.3 (16610.4.3.1.4)

  • Do you know of any workarounds? Interestingly, if createjs.Sound.play("tone"); is called within the fileerror callback, the sounds still plays?! However, this is a ridiculous hack which breaks any other attempts at actually handling errors.

How can I react and or work around the Never Auto-Play setting in desktop Safari?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

Thank you for the suggestion, however, I do not wish to preload sounds as my use case is streaming longer audio files. Which is also why I am using HTMLAudioPlugin.