Audio and web Audio

Source: Internet
Author: User

Doing H5 games will inevitably encounter the need to play background music or sound effects. The first response to this requirement was to use the audio tag in H5 to implement it, but in the process of implementation it was found that there were many problems.

1. Only a single audio can be played (on some devices, including iOS). What do you mean? This means that if you play the sound effects while playing the background music, the background concert is stopped. This is a very serious question.

2. not preloaded in iOS . This causes the H5 game to play sound in iOS, which can only be pulled off the audio data in real-time, which can have a certain effect on performance. And in the process of loading to set some audio properties will be an error.

3. On some devices, including iOS, can only be used in callback functions for events such as the native click , and calling the play method in normal program logic cannot take effect.

When the H5 game encounters these problems, it is really unable to play happily! iOS support for it is really bemoaned! No way, who let others have the App Store ...

Then I stared at the Web audio. This is not like audio can have a GUI, but in the game we do not need a GUI, so if she on iOS performance OK is very worthy of favor.

Search found, visual iOS support is fair.

Omit 1K words in the middle. Let's take a look at her features and quirks.

1. Support for audio is in place, supporting the synthesis of audio output and audio waveform.

2. Use an instance of Audiocontext or Webkitaudiocontext (depending on the browser's support) and then bind the audio. The audio file needs to be transmitted in HTTP, such as New XMLHttpRequest (). Need. Audiobuffer () is also required to buffer the audio files and to decode, connect to the output device, and then play back. The staff is very nice.

3. playback using Noteon (0), Chrome on Android does not support Noteon (0) and supports start (0) playback .

4. You can play multiple audio simultaneously .

5. an object can only be played once , if it needs to be repeated to generate a new object.

6.android native browser is not supported .

7.iOS support is perfect.

8. can be preloaded .

9. The first playback needs to be executed in the callback function of the click and other events , otherwise there will be no sound, which is not needed later.

Through the above introduction, you can know that audio and web audio accounted for half of each, it seems that can only be included in the bosom of ~

Use the preferred web Audio in practice (when using Noteon (0) to determine if this method is supported, start (0) if not supported, and Audio if not supported by the browser, such as a non-Chrome browser on an Android device, And do graceful downgrades, unsupported browsers play only a single audio.

Although do mobile games away from the IE6 of the destruction, can be a variety of equipment compatibility problems also really let people have some headaches have wood have ...

Audio and web Audio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.