How to configure the audio element in HTML5

In this article, we discuss how to configure the audio element in HTML5.

The <audio> element is used to play audio.The following is a sample implementation of the <audio> element.

<audio controls=”controls”>

                   <source src=”song.mp3″ />

                    You need a browser that supports HTML5!

</audio>{codeBox}

In this example,the <audio> element is configured with the controls attribute,which provides controls to start and stop the audio,to view and set the audio cursor location,and to set the volume.The <audio> element contains a <source> element that describes the audio source as .mp3.The <audio> element also contains text that is displayed on browsers that don’t support the <audio> element.

How to configuring the audio element in HTML5
How to configure the audio element in HTML5

One characteristic of audio is that the developer might play multiple audio files at the same time.

The <audio> element can be configured to provide the behaviour you need for your webpage. The following is the list of attributes you can use to configure the <audio> element to suit your needs.

  1. autoplay: Specifies that audio starts playing immediately.
  2. controls: Specify that the play/pause button, audio cursor, and maximize are displayed.
  3. loop:  Specifies that the audio repeats when it has reached the end of its stream.
  4. preload: Specifies how the audio should be loaded when the page loads. It can be set to auto, metadata, or none. The auto setting starts loading the audio when the page loads. the metadata setting loads only the metadata, and the none setting doesn’t load anything.
  5. src: Specifies the URL of the audio.

*

Post a Comment (0)
Previous Post Next Post