O'Reilly logo

Building HTML5 Games with ImpactJS by Jesse Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mobile Browser Sound Compatibility Issues

HTML5 audio is still in the early stages of being implemented across each browser. As you have seen, we still need to supply two different audio formats, and there is a good chance that a browser may not even support audio at all. This happens more on mobile than desktop browsers, but it’s still a good thing to keep in mind when setting up your audio.

To play it safe, you may just want to totally disable sound on mobile. You can do this with the following code in your main game module right before where we start our game:

if( ig.ua.mobile ) {
    // Disable sound for all mobile devices
    ig.Sound.enabled = false;
}

// Start the game
ig.main(...)

By setting ig.Sound.enabled to false, no sound files will be loaded or played back. If you don’t disable sounds on mobile browsers that don’t support audio correctly, your game may try to load and crash, or hang in the pre-loader screen. Also, setting sound to false is incredibly helpful when you are testing your game over and over again.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required