OFFICIAL GMS2 HTML5 Audio 2.2.2

Discussion in 'GameMaker Studio 2 Community Tech Support' started by rmanthorp, Jan 30, 2019.

  1. rmanthorp

    rmanthorp YoYo Games Staff Admin YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    246
    Beta IDE Release Notes
    Beta Runtime Release Notes
    Beta Opt-In FAQ
     (How to get on the Beta Channel)

    This topic is for the discussion of issues relating to HTML5 Audio. However, this does not replace our normal bug reporting system and you should report all bugs as normal using https://www.yoyogames.com/bug


    Goal: Send us feedback and sample projects for when things do not work as expected. Any browser issues when using other than Chrome / Safari?

    • Android and iOS no longer wait for streaming sounds to download during the loading screen - they now download async and are later queued and decompressed as required
    • Added audio_sound_is_playable() so you can query if a sound is actually ready to be played in browsers which require touch permission from players before streamed audio can be used

    There is no change to audio-handling on non-HTML5 platforms (though the new function will work on those platforms too), but for HTML5 we have changed how audio is loaded and played back to match the rules on the executing platform. The general rule of thumb is that a touch (or mouse) event must be recorded on the canvas for the game before any audio is played, and on iOS we need to decompress any audio before playback (as Apple have disabled streaming audio) which can introduce a delay. Again, see the manual for further details.

    ADMIN EDIT: The manual currently is missing the following additional information for iOS Audio:

    "HTML5 streamed audio will not play on iOS when the play request does not directly originate from a user interaction (i.e. a touch event, etc.). However, since GameMaker Studio 2 queues up click events and only handles them on the next frame, it is impossible to play streamed audio without the browser blocking it. To get around this, any HTML5 game run on an iOS browser will treat all streamed audio as unstreamed in the engine, with the exception of streamed audio not being preloaded (note that any .

    What this means is that if your game is running on an iOS browser, and - for example - you have 10 music tracks that are all set as streamed mp3 files. All 10 will be initialised like unstreamed audio would, but they won't be decoded immediately before the game loads, unlike normal streamed audio which would get preloaded/decoded immediately during the load screen phase.

    While this bypasses the iOS issue and prevents any huge increase in initial load times, it does mean that it may result in a state where your game has loaded, but certain streamed sounds may still be downloading or decoding. To deal with this you can use the GML function audio_is_playable(), which checks to see if a given sound can actually be played. On HTML5 this will return false if the sound is not fully loaded or decoded yet, and true if it is and can be played (on all other platforms it will always return true)."
     
    Last edited by a moderator: Jan 30, 2019
  2. Ricardo

    Ricardo Member

    Joined:
    Jun 20, 2016
    Posts:
    145
    @rmanthorp there is a way to suspend the download of a streamed sound? If you play a large sound, and then stop it (even before the download ends, the download will continue). E.g.:
    - set the micro web server speed to something very slow like "DSL";
    - play (audio_play_sound) a large music file that is set as streamed;
    - notice that the file download will start and the progress is shown in the micro web server. The sound will start playing once the download reach around 12%~
    - now stop the music (audio_stop_sound) before the download is complete. The music stop immediately, but the download of the file continues in the micro web server until it reach 100%, consuming unnecessary bandwidth and resources.
     
  3. Ricardo

    Ricardo Member

    Joined:
    Jun 20, 2016
    Posts:
    145
    I found a weird behavior testing streamed sounds on my phone (Galaxy S8, Chrome 71.0.3578.99). When a streamed sound is played, the download of the file is duplicated in the micro web server. If the network speed is set to "No limit", is easy to get the file downloaded twice at 100%. If speed is set to something lower, the duplicated download may stop after a while. This doesn't affect the audio playback in any way, the sound is played as expected.
    In "Samsung Internet", audio_sound_is_playable() returns false in the first touch, then return true in subsequent attempts, but the sound never plays (and it doesn't appear in the micro web server).
    On iOS (old iPad mini 2), everything is working as expected in Chrome.
     
    chirpy likes this.
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,408
    @Ricardo : Could you please file a bug report for each issue? Link to your posts in this topic too.
     
    Ricardo likes this.
  5. chirpy

    chirpy Member

    Joined:
    Oct 6, 2016
    Posts:
    108
    I've switched to Mac IDE 2.2.2.390 runtime 2.2.2.302 but the IDE can't find audio_is_playable() function.

    With a bit of try and error I'm sure it's called "audio_sound_is_playable".
    [Edit: sorry I totally didn't read this thread through; it's mentioned in the previous comments apparently, only a typo in the temp documentation part.]
     
  6. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
    There is an updated beta release out now, so please update when you can - https://forum.yoyogames.com/index.php?threads/gms2-version-2-2-2-beta-release.58932/ for further info.

    It doesn't contain any specific fixes for this audio functionality change, but it does contain very important stability fixes to stop code editor crashes which might be impacting on your use of the beta version, so we would strongly advise you update. It does also contain the missing manual information mentioned in the first post on this thread.

    We're still investigating if we can reliably do the stop of downloads in progress, btw. However, it does look like on most platforms this isn't something we can control, as it's the browser which does the download on the game's behalf adn not all the browsers support the ability to automatically cancel a download in progress, so we're currently not sure adding in a function to suggest we can control this (and potentially that function only working for specific browsers on specific platforms) is a good idea. More likely to make audio_stop_sound() automatically attempt to stop the file, but with the documentation saying this won't happen on most browsers/platforms.

    The webserver showing the download twice issue: we're looking into the "messaging" of this within the web server application, but I can tell you that you're not downloading the sound twice - the first entry is the request for the sound's header (a tiny amount of data) and then the second one is the actual download. More info can be found here, as we have now determined this is not fixable: https://bugs.yoyogames.com/view.php?id=30487

    If you do have any other HTML5 audio issues with this 2.2.2 update, let us know asap, please!
     
    Last edited: Feb 13, 2019
    True Valhalla likes this.
  7. True Valhalla

    True Valhalla Full-Time Developer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    306
    I'll be testing the HTML5 audio changes on Monday, this stability fix should make it less painful.
     
  8. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
    Any update? How did you find things?
     
  9. True Valhalla

    True Valhalla Full-Time Developer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    306
    It took some time to get my audio working as intended but I haven't encountered any major roadblocks yet. Initial tests on primary platforms seem promising.

    One of the more tedious issues I'm dealing with when porting my GMS1 projects to GMS2 is that the bitrate on sound files is not being honoured between versions. The bitrate is reset to 128kbps so I have to manually update every single asset. I reported this bug 6+ months ago.
     
    Last edited: Feb 15, 2019
  10. chirpy

    chirpy Member

    Joined:
    Oct 6, 2016
    Posts:
    108
    I still haven't found time to sort out a proper report, but: pressing Chrome reload button on PC while my game's audio is playing had been causing issues. Chrome sometimes (if not always) hangs, while reloaded runner's spitting messages about audio.

    I'm not sure whether it's physics or audio that's not cleaned up properly; will try to test more and file a report. If anyone can confirm it's somewhat a known issue please let me know.
     
  11. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
  12. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
  13. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
  14. True Valhalla

    True Valhalla Full-Time Developer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    306
  15. Dan

    Dan YoYo Games Staff YYG Staff

    Joined:
    Apr 15, 2016
    Posts:
    228
    Are you seeing an actual issue with that change?

    We updated our Firefox installs yesterday, after learning that, and found no real change in practice, as Firefox seems to allow the "can the runner do the initial click for you?" system we added already in 2.2.2. So for us music continued to play as soon as the game was loaded.
     
  16. chmod777

    chmod777 Member

    Joined:
    Aug 26, 2016
    Posts:
    184
    In the Firefox options, there is something like: "Prevent audio to be played automatically". This box was not ticked for me after update, maybe it's only for new Firefox users.

    But everything seems to work as expected in GameMaker when the option is enabled, both compressed and uncompressed sounds play fine.

    Just a note... For games created before all these audio changes in GameMaker and which only use uncompressed sounds, things will continue to work (at least for now) as Firefox seems to only prevent autoplay from HTML5 <audio> tags, not WebAudio.
     
  17. VacantShade

    VacantShade Member

    Joined:
    Aug 8, 2016
    Posts:
    12
    I've noticed an issue, even with the new updates. Everything works fine on my devices, but I've been able to replicate and pinpoint the issue on my friend's device. For reference, he is using iOS Safari.

    My game has multiple sound effects as ".wav" files. These all work fine.
    The problem is with the longer music tracks, as ".mp3" files. Some work and some don't. I've used the new function "audio_is_playable()" to test every music track, and the ones that refuse to play return "false".
    What was strange was that some worked and some didn't, so I investigated and found that all the ones that played were both under 1:00 and less than 1mb in the final HTML5 output folder. Any that did not work were longer than 1:00 and/or larger than 1mb.

    I've tried different loading settings, like "uncompressed - not streamed", "uncompressed on load - not streamed", ect, with no solution.
    Instead, I trimmed all the music tracks down to less than 1:00, with their final sizes now less than 1mb, and all sound works perfectly. Obviously, this isn't ideal as the tracks no longer loop smoothly. But I think it proves what the issue is.

    I can post an official bug report, but just wanted to check here first, in case this is a known limitation of some browsers/os that I am just unaware of.
    Thanks!
     
  18. Ricardo

    Ricardo Member

    Joined:
    Jun 20, 2016
    Posts:
    145
    When you call audio_is_playable(sndID) I think the sound will start to decode, and I also noticed it'll return false with large sounds (as musics) in iOS. The trick is to have plan B for when audio_is_playable() returns false. It may be a dummy instance you create with an alarm that will keep checking the sound ID until it returns true, then you can play it.
    Important: do NOT play a sound without first test it using audio_is_playable(), it may sometimes play, but the returning ID will be invalid and you won't be able to stop/manage it later.
     
  19. VacantShade

    VacantShade Member

    Joined:
    Aug 8, 2016
    Posts:
    12
    Thanks for the reply!
    Just to clarify, I have a script "music_handle" that I run every step. This figures out what music should play, since it changes multiple times in the same room. If a music change is needed, it stops the current track and it updates a variable with the id of the desired music track. Then every frame it checks if that music is playing, and if not, runs the audio_is_playable() function, and plays it if possible. If not, it will give a visual cue that the function returned false.
    So it doesn't seem to be just a matter of time for the music to load, because I've had the function check the same music for 5-10 Minutes straight, every frame, and it always returns false. But changing a music track from a length of 1:15 to 0:59 seems to instantly solve the issue...

    Any thoughts on something else I could try?
     
  20. Ricardo

    Ricardo Member

    Joined:
    Jun 20, 2016
    Posts:
    145
    Oh, I see. So it seems like you may have found a bug that need to be properly reported. I have a few musics on my game (2 to 5 minutes) but I haven't had that specific issue of audio_is_playable() returning false all the time.
     
  21. chmod777

    chmod777 Member

    Joined:
    Aug 26, 2016
    Posts:
    184
    Which version of iOS are you using as I remember they said older versions of browsers would not work?
    Also, does audio_system_is_available() return true?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice