kittykatattack / ga

The world's tiniest, cutest and funnest game engine
453 stars 85 forks source link

audio broken on safari #73

Open increpare opened 5 years ago

increpare commented 5 years ago

01_treasureHunter.html doesn't play audio in safari 12.1.1 for me, but does in Chrome/Firefox. (Usual browser audio sandboxing stuff, has to be somehow enabled in response to an event).

No error messages about it in the js terminal.

IIRC, this is my general handle for fixing the sound in puzzlescript - I call it whenever the user tries to play something (this means sometimes it skips the first sound - I could call it on startup as well I guess):

//unlock bullshit
function ULBS(){   
  if (AUDIO_CONTEXT.state === 'suspended')
  {
      var unlock = function()
      {
        AUDIO_CONTEXT.resume().then(function()
          {
            document.body.removeEventListener('touchstart', unlock);
            document.body.removeEventListener('touchend', unlock);
            document.body.removeEventListener('mousedown', unlock);
            document.body.removeEventListener('mouseup', unlock);
            document.body.removeEventListener('keydown', unlock);
            document.body.removeEventListener('keyup', unlock);
          });
      };

      document.body.addEventListener('touchstart', unlock, false);
      document.body.addEventListener('touchend', unlock, false);
      document.body.addEventListener('mousedown', unlock, false);
      document.body.addEventListener('mouseup', unlock, false);
      document.body.addEventListener('keydown', unlock, false);
      document.body.addEventListener('keyup', unlock, false);
  }
}

)