HTML5 audio elements How to use JS and jquery to control their events

Source: Internet
Author: User

Objective:

Every time you meet a problem, the thought is how to solve it? The best way is to query the network media, the better way is to let their memories, only their own understanding of the really belong to their own. To make an order reminder function, do not use audio-related plugins, although the plug-in countless, or like their own blind toss. (to some invisible link, said to have the effect of promotion, this article original website address:www.pushself.com)

Listen to a blog friend said that the weekend reading volume of the blog significantly decreased, the weekend good time does not go out to bubble sister's affirmation is nanyanzhiyin. Let's revisit the basic properties of the audio tag.

Definition and usage

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

Example code: <  src= "Someaudio.wav"> Your browser does not support the audio tag.  </audio>
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.

Property
Properties value Description
AutoPlay AutoPlay If this property appears, the audio plays immediately when it is ready.
Controls Controls If this property appears, the control is displayed to the user, such as the play button.
Loop Loop If this property appears, the playback starts again each time the audio ends.
Preload Preload

If this property appears, the audio loads when the page loads and prepares to play.

If you use "autoplay", the property is ignored.

Src Url The URL of the audio to play.
Event method (temporarily not expanded)

Play () playback

Pause () pauses

Actual combat, the code is only for the next imitation
JS Sample Code<AudioID= "Audio"src= "No.mp3">Tell you how many times, you just do not listen, so the low version of the browser is not replaced, what do you want to do?</Audio>    <Scripttype= "Text/javascript">        varAudioele=document.getElementById ("Audio");    Audioele.play (); //PlayAudioele.pause (); //Pause    </Script>
jquery Sample Code<AudioID= "Audio"src= "No.mp3">Tell you how many times, you just do not listen, so the low version of the browser is not replaced, what do you want to do?</Audio>    <Scripttype= "Text/javascript">        varAudioele= $("#audio")[0];    Audioele.play (); //PlayAudioele.pause (); //Pause    </Script>

Why does jquery need a 0? The JS operation obtains the audio object, the jquery selector obtains the jquery object, the 0 object is the corresponding node object. Therefore, it is not possible to use jquery objects directly, which needs to be supplemented with a bit of basic knowledge. (to some invisible link, said to have the effect of promotion, this article original website address:www.pushself.com)

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.