• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

OFFICIAL GMS2 HTML5 Audio 2.2.2

rmanthorp

GameMaker Staff
Admin
GameMaker Dev.
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:

Ricardo

Member
@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.
 

Ricardo

Member
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

Member
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.]
 

Dan

GameMaker Staff
GameMaker Dev.
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:

True Valhalla

Full-Time Developer
GMC Elder
I'll be testing the HTML5 audio changes on Monday, this stability fix should make it less painful.
 

True Valhalla

Full-Time Developer
GMC Elder
Any update? How did you find things?
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:

chirpy

Member
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.
 

Dan

GameMaker Staff
GameMaker Dev.
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.
 

chmod777

Member
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.
 

VacantShade

Member
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!
 

Ricardo

Member
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!
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.
 

VacantShade

Member
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.
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?
 

Ricardo

Member
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?
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.
 

chmod777

Member
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?
 

VacantShade

Member
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?
Its the latest version of iOS, 12.2 I believe. Its running through Safari.
I tried doing a check with audio_system_is_available(), and that seems to be the issue, it is returning false all the time. I've divided the audio into groups, and those seem to load without a problem. But yeah, the audio system doesn't seem to be allowing the audio the play, and it doesn't seem to ever come on while running. I will continue to try different settings on the device itself to see if that is the problem...
Thanks for pointing me in the right direction of what to check!
 

Ricardo

Member
Its the latest version of iOS, 12.2 I believe. Its running through Safari.
I tried doing a check with audio_system_is_available(), and that seems to be the issue, it is returning false all the time. I've divided the audio into groups, and those seem to load without a problem. But yeah, the audio system doesn't seem to be allowing the audio the play, and it doesn't seem to ever come on while running. I will continue to try different settings on the device itself to see if that is the problem...
Thanks for pointing me in the right direction of what to check!
Remember you can't try to play a sound before a touch event happen (say mouse release). If you do that, the browser will lock the audio system. So make sure you aren't trying to play music/sound at the very beginning of your game.
 
I don't know how on earth I can hear audio in my chrome browser. I am using IDE v2.2.3.436. The latest version at this point.
When testing on the desktop, run the iis server locally and move the folder created by create excutable to access 127.0.0.1 in chrome and the audio_sound_is_playble () function will always return false.
Does someone know how?
 
It seems that audio for HTML5 still doesn't work as expected in version 2.2.3. I have a game https://rozensoftware.com/Game/Druid/index.html in which audio can be heard only on current version of MS Edge web browser. Firefox and Chrome don't produce any sound, logging in the console that 'audio_play_sound_at failed. WebAudio Context suspended - user must interact with the page before audio can be played.', what obviously happened..

On the other hand, GM runner crushes (black screen) when mp_grid_path function returns false. Debugger console prints:

Code:
Error: Error: Can't END path in a blocked grid position. (mp_grid_path)
--------------------------------------------------------------------
    function _pJ("Error: Can't END path in a blocked grid position. (mp_grid_path)")
    function _vn([instance], 0, 25, 1202, 1175, 666.7999999999979, 1103.1999999999873, 0)
    function _m6([instance], [instance])
    function(769, 0, [instance], [instance])
    function(769, 0, [instance], [instance])
    function(769, 0)
    function _uk3()
    function _0k3()
    function _Gj3(97806.42051319999)
Druid.js:3572:500
###game_end###-2
Hope that will be fixed soon.
 

chmod777

Member
It seems that audio for HTML5 still doesn't work as expected in version 2.2.3. I have a game https://rozensoftware.com/Game/Druid/index.html in which audio can be heard only on current version of MS Edge web browser. Firefox and Chrome don't produce any sound, logging in the console that 'audio_play_sound_at failed. WebAudio Context suspended - user must interact with the page before audio can be played.', what obviously happened..
It does work for me on Firefox, if I click somewhere on the page during the loading screen. If I don't, then yeah there is no music, but Ricardo has already explained why:

Remember you can't try to play a sound before a touch event happen (say mouse release). If you do that, the browser will lock the audio system. So make sure you aren't trying to play music/sound at the very beginning of your game.
 
It does work for me on Firefox, if I click somewhere on the page during the loading screen. If I don't, then yeah there is no music, but Ricardo has already explained why:
Yes, you're right. This is a very important message. I try to play a music in my app as soon as possible. That's why it doesn't work. Now, I'm working on a fix for that.
Thank you.
 
Top