HTML5 's <audio> audio "pit"

Source: Internet
Author: User

<audio> tags are a very meaningful feature of HTML5. Farewell to the flash of the era. Its properties are:

AutoPlay: Play immediately after audio is ready

CONTROLS: This property appears, displaying the playback controls to the user.

Loop: Whether to re-play at the end of the audio

Preload: If this property appears, it is loaded when the page loads.

src: The URL of the audio to play.

Methods are:

Load (): New load resource.

Play (): Start playback.

Pause (): pauses playback.

These are the basic points of knowledge. If we need to let the audio play automatically. In the iphone, we found that it was impossible to achieve .

Here the solution is on this page


document.addeventlistener (' Touchstart ',function(){

Document.queryselector ("#musicBox"). Play ()
}, true);  

The ability to implement playback (meaning that it must be triggered manually).

If triggered automatically, the event mechanism has to be understood.

In the mouse event:


var Elem = document.getElementById (' pp '); Elem.addeventlistener (' click ', function () {Alert (111)}, True); var evt = document.createevent (' MouseEvent '); evt.initmouseevent (' Click ', True, true, window, 1, 12, 3 7, 0, False, False, true, FALSE, and NULL); Elem.dispatchevent (EVT); 

In the same vein, in the Touch event:

varElem = document.getElementById (' pp ');
Elem.addeventlistener (' Touchstart ',function(){
Alert (111)
},true);
varEVT = document.createevent (' touchevent ');
Evt.inittouchevent (' click ',true,true, window, 1, 12, 345, 7, 220,false,false,true,false, 0,NULL);

elem.dispatchevent (evt);

Implement a function point similar to jquery's trigger



HTML5 's <audio> audio "pit"

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.