frnsys / half_earth

Half-Earth Socialism: The Game, for Half-Earth Socialism (Verso 2022)
GNU Affero General Public License v3.0
37 stars 6 forks source link

Audio playback issues #214

Closed frnsys closed 2 years ago

frnsys commented 2 years ago

Primarily these two:

I think these both have to do with async loading/playback?

frnsys commented 2 years ago

From: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/load

The process of aborting any ongoing activities will cause any outstanding Promises returned by play() being fulfilled or rejected as appropriate based on their status before the loading of new media can begin. Pending play promises are aborted with an "AbortError" DOMException.

So according to that (and also this) the easiest (though not ideal) way is to just catch the play error, e.g.:

    this.audio.play().catch((_err) => {
      // Ignore
    });

This might also suppress the error that Safari gives...though as I understand it that error occurs if trying to play something before the user has interacted with the page, but this isn't the case as we wait until the player starts the game (i.e. clicks "New Game" or "Continue", which should count as an interaction).