HTML5 audio function, html5 audio

Source: Internet
Author: User

HTML5 audio function, html5 audio
HTML5 audio Functions


1. Web audio

Until now, there is still no standard for playing audio on the webpage.

Today, most audios are played using plug-ins (such as Flash. However, not all browsers have the same plug-ins.

HTML5 specifies a standard method to include audio through the audio element, that is, HTML5 provides the standard for playing audio.

The audio element can play audio files or audio streams.


2. Audio Format

Currently, the audio element supports three audio formats:

IE 9

Firefox 3.5

Opera 10.5

Google Chrome 3.0

Safari 3.0

Ogg Vorbis

 

 

MP3

 

 

Wav

 

 


3. How to work

To play audio in HTML5, You need:

<audio src="song.ogg" controls="controls"></audio>

The control attribute allows you to add playback, pause, and volume controls.

The content inserted between <audio> and </audio> is displayed by browsers that do not support the audio element:

<audio src="song.ogg" controls="controls">Your browser does not support the audio tag.</audio>


The above example uses an Ogg file, which is applicable to Firefox, Opera, and Chrome browsers.

Make sure that the audio file is MP3 or Wav in Safari.

The audio element allows multiple source elements. The source element can be used to link different audio files. The browser uses the first recognizable format:

<audio controls="controls">  <source src="song.ogg" type="audio/ogg">  <source src="song.mp3" type="audio/mpeg">Your browser does not support the audio tag.</audio>

Note: Internet Explorer 8 does not support audio elements. In IE 9, support for audio elements is provided.

4. attributes of the <audio> tag

Attribute

Value

Description

Autoplay

Autoplay

If this attribute appears, the audio will be played immediately after it is ready.

Controls

Controls

If this attribute is displayed, the control, such as the play button, is displayed to the user.

Loop

Loop

If this attribute is displayed, the video is played again whenever the audio ends.

Preload

Preload

If this attribute is displayed, the audio is loaded when the page is loaded and ready for playing.

If "autoplay" is used, this attribute is ignored.

Src

Url

The URL of the audio to be played.


5. instance demonstration
<! DOCTYPE html> 






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.