HTML5 audio tags How to use? HTML5 Auto-Play Implementation code instance

Source: Internet
Author: User
HTML5 audio tags How to use? HTML5 audio Tag Auto play and use tutorial, below to start our article introduction, mainly introduces the use of HTML5 audio tags, as well as the HTML5 audio tag auto-play and pause tutorial detailed

Definition of HTML5 audio label usage:

<audio> tags define sounds, such as music or other audio streams.

HTML5 Audio Tag Instance

A simple HTML 5 audio:

<audio src= "Someaudio.wav" > your browser does not support audio tags. </audio>

HTML5 the properties of the audio tag:

Here's a tutorial on using HTML5 audio tags

HTML5 Audio tab Auto Play and Pause

This has a mobile side of the H5 activity page, one of the requirements is: Open the page after the background music will automatically start playing, click the Music icon button to control its play and pause.

Mobile, music playback, auto play and pause, audio tag is required, so directly write:

<code class= "language-html" ><i class= "Icon-music-outer" >      <i class= "forbid Icon-music" ></i >       <audio loop autoplay= "AutoPlay" Controls id= "Bgmusic" src= "./music/musicmin.mp3" >       </audio>  </i>  <script>      var $music = $ ('. Icon-music-outer ');      var $forbid = $music. Find ('. forbid ');      var audio = document.getElementById (' Bgmusic ');        $music. On (' click ', Function () {          if ($forbid. Hasclass (' Icon-music ')) {              $forbid. Removeclass (' Icon-music '). AddClass (' Icon-forbidmusic ');          } else {              $forbid. Removeclass (' Icon-forbidmusic '). addclass (' Icon-music ');          }            if (audio.paused) {              audio.play ();              Return          }          audio.pause ();      });  </script>  </code>

In the Chorme browser simulation, click on the small speaker, you can synchronize the audio tag to play and pause, but also to automatically play.

So put on the mobile phone measured some, the result .....

Everything is OK on the Android phone;

But on the Apple phone, just when you enter the page is not automatically played

Later after a lot of information to know, this is because Apple to prevent users in the traffic environment, this will lead to traffic theft, so it is forbidden to automatically play audio, unless the user actively triggered. Of course, there are ways to achieve the demand, after all, is in the people's browser run up, under the eaves, have to bow Ah!

A further introduction of the developer JS file, the overall wording is as follows: JQ and native notation

<! DOCTYPE html>

Differences between HTML 4.01 and HTML 5

The <audio> tag is a new label for HTML 5.

Hints and Notes

Tip: You can place text content between the start and end tags so that older browsers can display information that does not support that tag.

"Recommended"

What is the role of the HTML pre tag? HTML PRE tag usage and its properties

What does the HTML li tag do? Introduction to HTML Li Tag usage and properties

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.