kittykatattack / hexi

Make games the fun way!
MIT License
554 stars 83 forks source link

WebAudio not loading on iOS safari #56

Open Digital-Odyssey opened 6 years ago

Digital-Odyssey commented 6 years ago

Hey,

I can't get any audio to play on iOS devices. Does the "Audio Context Monkey Patch" code in hexi engine need to be updated?

kittykatattack commented 6 years ago

@PulsarMedia I'm not sure, are you getting any errors? The repo for the sound module is here: https://github.com/kittykatattack/sound.js

Digital-Odyssey commented 6 years ago

My game loads up and plays fine in iOS safari on my iPhone 6 but the audio doesn't work. And i am unable to determine if there are any errors since i can't run remote debugging on my Windows PC. My audio files are in MP3 format but i am not sure if they are compressed with low level complexity which apparently is what mobile safari supports - perhaps that could be the issue?

kittykatattack commented 6 years ago

I'm also not able to test this at the moment. You could perhaps test a different sound engine, like howler just to see whether the problem is at the file level or the encoding level.

Digital-Odyssey commented 6 years ago

Hi, i cant get my sound files to load with Howler - apparently it works primarily with WebM files.

Is there another library i cant test?

kittykatattack commented 6 years ago

@PulsarMedia Ok, that's weird! HowlerJS plays everything. I wonder if there's a problem with your sound files? Have you tried this?

https://stackoverflow.com/a/18628124/1282216

Digital-Odyssey commented 6 years ago

ok i tried a simple audio tag element and it looks like my audio file doesn't play on mobile devices. It plays if i load the file directly through the URL but not through code.

Do you have any recommendations on how to properly compress mp3 files for mobile?

kittykatattack commented 6 years ago

@PulsarMedia I'm really sorry, I haven't come across this problem before Can anyone out there reading this offer some help??

Digital-Odyssey commented 6 years ago

Actually nevermind about my previous post i was able to get my mp3 file to work on iOS safari through the audio tag just fine so there is nothing wrong with my mp3 file. I did however learn that safari on iOS does not autoplay audio files due to bandwidth concerns and that the Webaudio api requires a touchend event to activate audio on iOS mobile devices - im going to play around with this and see if i can get my audio to play through a touchend event.

Digital-Odyssey commented 6 years ago

Do you happen to have any game demos with working audio on iOS safari? I tried adding a simple touched event to the window to load my audio but doesn't seem to work.