daleharvey / pacman

HTML5 Pacman
Do What The F*ck You Want To Public License
704 stars 472 forks source link

Game not works in mobile safari #7

Open thefabhub opened 9 years ago

thefabhub commented 9 years ago

Hi, the game stuck on loading on mobile safari (ipad and iphone), disabling the audio files loading make it playable but no audio of course ;). Any clues?

nicholaswmin commented 9 years ago

mobile browsers on iOS are restricted to playing sounds ONLY when using a user-initiated event, e.g a click,scroll etc. There is no workaround for this since it's a system-wide restriction imposed by iOS itself.

xavierjs commented 6 years ago

Hi, I have the same issue with an IPAD PRO on Safari 11. You can fix it in pacman.js, line 704 you have:

        f.addEventListener("canplaythrough", progressEvents[name], true);
        f.setAttribute("preload", "true");
        f.setAttribute("autobuffer", "true");
        f.setAttribute("src", path);
        f.pause();        

replace this by :

        f.addEventListener("canplaythrough", progressEvents[name], true);
        f.setAttribute("preload", "true");
        f.setAttribute("autobuffer", "true");
        f.setAttribute("src", path);
        if (f.load){ //SAFARI FIX
            f.load();
        }
        f.pause();        

Then it works like a charm :)