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