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

HTML5 Game no audio on mobile devices

C

Copperbolt

Guest
Hi,

I have tested my HTML5 game on multiple mobile devices and it seems there is no audio.
Does somebody know the solution for this? Is the fault in the game, the audio formats or the mobile device itself?
 

jadegames

Member
Hi Copperbolt. I've had a similar issue and think perhaps I might be able to help. I've been able to play audio on android devices using the Chrome browser successfully. Can you ensure that you have the New Audio Engine is ticked under Global Game Settings and that for your audio, you pick "Compressed - Not Streamed..." then try again. Also, I'm using .mp3 files which appear to work OK.

I'm having issues with HTML5 audio not working on iOS devices though. I've found a few posts on this
http://gmc.yoyogames.com/index.php?showtopic=606885
http://gmc.yoyogames.com/index.php?showtopic=636879&hl=

But I've not been able to get audio working on iOS 9+. I've enabled the New Audio Engine as the GML engineer suggests in the posts above but still nothing. Tried using the exAudio extension, got that to work in Chrome (Windows + Android browser versions) but not on iOS. In my code, the audio plays after a "Left Mouse Release" event occurs, but that doesn't work. I've tried duplicating the code into a "Left Mouse Pressed" code, but that doesn't work either.

I'm using the version of GML 1.4.1757, I've read the release notes for the latest version but there is no mention of any "HTML5 audio working for iOS"

Anyone have any ideas?
 

jadegames

Member
Sorry to keep bumping this, I did a little troubleshooting and found a way of getting logs from an iPhone. JConsole.com pretty using, it provides the same information as if you ran it locally in GameMaker.

After I click the button that should start audio I can see the error "Audio_PlayUnstreamed exception: TypeError: Value is not of type AudioBuffer" which after a bit of Googling seems to suggest that I'm not setting the buffer correctly before running my code, but I'm using GML code for all of this:" audio_play_sound(snd_bkg, 10, false);"

Anyone else attempted to troubleshoot this HTML5 issue on a real (not simulated device, in every simulation I've run it works fine) and seen the same thing I have?

I'll do more investigation and report back...
 

rIKmAN

Member
Anyone else attempted to troubleshoot this HTML5 issue on a real (not simulated device, in every simulation I've run it works fine) and seen the same thing I have?
I came across this problem using another language, and it's not specific to GM - although they should really have implemented a fix internally or at least mention this in the docs.

There is info on the issue in the Apple docs near the bottom of this page but I'll quote relevant part...
Note: On iOS, the Web Audio API requires sounds to be triggered from an explicit user action, such as a tap.
Calling noteOn() from an onload event will not play sound.
What this means is that you can't play sound yourself without input from the user (ie. press a button etc)
The "official" explanation is to protect users from big downloads when using mobile tariffs and from noisy websites, but we all know the real reason is that Apple don't want games being played properly through the browsers on their devices as it would allow people to "publish" HTML5 games and let users play them without going through the App Store.

Here is a link which explains how to unlock web audio, but I'm not sure how that could be added to GM itself.
You could edit the generated html files to add the listeners to the exported project though?

Hope that helps.
 

jadegames

Member
Sorry...as ever it was a stupid mistake that made it not work. Audio for HTML5 mobile devices (both Android and iOS at least, I don't own a Windows phone) does work in GM:S.

So annoying that I've spent about 2 weeks trying to figure out audio when the fix was...well not staring me in the face, but was really wasn't as tricky as I thought it was.

So for anyone else struggling out there who wants to do this, you don't need a .js extension or anything like that to play HTML5 audio in GM:S.

- Add a sound resource to your project, make sure it's a format that can be played by the mobile device (i.e. .mp3 for iOS & android) as stated http://gmc.yoyogames.com/index.php?showtopic=606885&p=4487745
- For your sound resource, at least for me, under Properties, I could only get sound to play under the "Compressed not streamed" setting with correct sample rate.
- Use the new Audio Engine not the legacy one and write that if else loop like the documentation tells you to capture any legacy devices so it they can have audio - don't discriminate :)
- Create a Left Mouse Release event for the area of screen you have assigned for this and run the code audio_play_sound(snd_bkg, 10, false); for example

Audio will work.

Phew!!! Can move on with my life now!
 
Sorry...as ever it was a stupid mistake that made it not work. Audio for HTML5 mobile devices (both Android and iOS at least, I don't own a Windows phone) does work in GM:S.

So annoying that I've spent about 2 weeks trying to figure out audio when the fix was...well not staring me in the face, but was really wasn't as tricky as I thought it was.

So for anyone else struggling out there who wants to do this, you don't need a .js extension or anything like that to play HTML5 audio in GM:S.

- Add a sound resource to your project, make sure it's a format that can be played by the mobile device (i.e. .mp3 for iOS & android) as stated http://gmc.yoyogames.com/index.php?showtopic=606885&p=4487745
- For your sound resource, at least for me, under Properties, I could only get sound to play under the "Compressed not streamed" setting with correct sample rate.
- Use the new Audio Engine not the legacy one and write that if else loop like the documentation tells you to capture any legacy devices so it they can have audio - don't discriminate :)
- Create a Left Mouse Release event for the area of screen you have assigned for this and run the code audio_play_sound(snd_bkg, 10, false); for example

Audio will work.

Phew!!! Can move on with my life now!
Hi jadedgames - and anyone else who might be able to help :)

Thanks for your tips above. I wonder if you are still getting audio to work on HTML5 across devices?... I've managed to get audio working on Android and desktop, but I cannot get it working on IOS devices at all. Does yours still work? Following your advice:
1. Sound files are uploaded to server in mp3 and ogg format automatically.
2. I've set sound to "compressed not streamed" --- not sure what you mean by correct sample rate though?
3. Using the new audio engine and then testing audio_system() to see if GM has auto switched to the legacy system, then if else looped based on the audio system active to determine whether to play sound with new or legacy code.
4. I activate audio using release event - as I say, working like a dream on my desktop and Android, but not for IOS devices...

Any tips / steer in the right direction would be very much appreciated :)

Thanks
 
*sigh*

Sorry, never mind! As a non apple user I wasn't aware my darling wife uses a mute button on the side of the device. Lol. All working ok - thanks again for the tips! :)
 
  • Like
Reactions: SVG
Top