HTML and CSS Reference
In-Depth Information
Why Not Support a Single Format?
As a web developer, it's unimaginably frustrating that no single audio (or video for that matter) format is suppor-
ted in all browsers. The primary reason for this is patents. Encoding and decoding audio data to and from the
MP3 audio format, by far the most popular format, is a process protected by patented technology owned by the
Fraunhofer Institute. For this reason the open-source Firefox browser has chosen not to support the MP3 file
format in its browser, but instead support the open OGG file format for audio.
Other browsers such as Internet Explorer and Safari unfortunately don't support OGG. The reason for this is
fuzzy; some people guess it's because Microsoft and Apple don't want the open-source format, which some
claim is less performant from a technical perspective, to “win.” The assumption on everyone's part is that the
first file format supported in all browsers will win the format battle because developers will be happy to have
only one format to support.
Understanding the Limitations of Mobile Audio
With the basics of the HTML5 audio tag covered, there's good news and there's bad news. The good news is
that the <audio> tag is supported by current versions of iOS and Android. The bad news is that support is
severely crippled in several instances.
The first issue is that iOS has the limitation to require sounds to be loaded and played only from a user-
initiated action. Furthermore iOS plays only a single channel of HTML5 audio at a time. On Androids newer
versions than 2.3, the limitations aren't as severe, but the latency associated with loading and swapping audio
files means effectively the same limitations as iOS applies.
As you can imagine, this severely limits the sound capabilities of mobile devices for games: You must play
sound effects whenever they are appropriate (such as when a missile hits an enemy) and not just in response to
a user action.
The workarounds to still allow some audio playback are quite limited, but you can get some amount of audio
playback on mobile from a game perspective using the concept of audio sprites, as shown in the section “Using
Sound Sprites.”
All this changes in iOS 6, which will have support for some implementation of Audio Data API. Android
will also support the Audio Data API at some point in the future, but currently sound sprites are the best you
can use as of this writing.
Building a Simple Desktop Sound Engine
Before delving into the contortions necessary to get audio playing on a mobile device, it's worth taking a look
at what's involved in playing sound effects via the <audio> tag on the desktop.
Using Audio Tags for Game Audio
One of the problems with Audio objects from a game perspective is that each object can play only one sound at
a time. This means that if you want to play the same sound effect twice at almost the exact same time (because,
for example, two missiles just blew up) you can't if you use a single audio element.
Search WWH ::




Custom Search