The audio tag of H5 is compatible with all browser methods.

Source: Internet
Author: User

The audio tag of H5 is compatible with all browser methods.

Front-end Communication Group, which provides a large number of documents, books, and materials. We look forward to your participation! GROUP: 127768464

As required by the project, a new webpage sound function was just launched recently, and the H5 new tag <audio> </audio> was used. However, audio can only support browsers over IE8, how can low-version browsers support this? Next I will introduce my solutions.

Two solutions have been found through online data collection. One is to introduce <script src = "// api.html5media.info/1.1.8/html5media.min.js"> </script> to the page head for processing compatibility, use the <embed> </enbed> label. After actual tests, the first method of Introducing JavaScript seems to fail to achieve the expected results. If you are interested, you can try it. It may be that my operation is incorrect. I am using the second method, using <audio> </audio> and <embed> </enbed> together, for IE8 and later browsers, <audio> </audio> is used to play audio. For IE8 and earlier browsers, <embed> </enbed> is used.

Through actual observation, I found that the embed tag in IE8 and the following browsers is actually embedded in Windows media player, the js method for playing, pausing, and stopping media player is the method for Operating Windows media player. It is a bit pitfall. I found that the autostart = "false" of the embed label is not very well supported in other browsers, this is when the page is loaded, it will automatically sound. The solution to this problem is [if lte IE 8] to determine the browser version, the <embed> </enbed> label is used only in IE8 and earlier browsers. The <embed> </enbed> label is not loaded in IE8 or later browsers. The actual code is as follows:

<div style="display:none">        <audio id="a_player_audio" src="a.mp3"></audio>        <audio id="b_player_audio" src="b.mp3"></audio>        <audio id="c_player_audio" src="c.mp3"></audio>        <audio id="d_player_audio" src="d.mp3"></audio>        <audio id="e_player_audio" src="e.mp3"></audio>    </div>    <!--[if lte IE 8]>    <div>-->

The Control Method of js is slightly different. Playing is the play () method. For the Stop playback method, audio only provides the pause method pause (), while Windows media player provides the pause () method () method and stop () method.

All of the above are my summary of experience. If you have any mistakes, you are welcome to correct them, or you can exchange some ideas. ,

  Front-end Communication Group, which provides a large number of documents, books, and materials. We look forward to your participation! GROUP: 127768464

Related Article

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.