Audio and Video Tags

Audio and Video Tags

·

5 min read

Audio Tag -

The <audio> HTML element is used to embed sound content in documents. It may contain one or more audio sources, represented using the src attribute or the <source> element: the browser will choose the most suitable one.

We will also talk about <source> element also.

This is simple example of <audio> tag using some attribute :-

The content inside the opening and closing tags is shown as a fallback in browsers that don't support the element.

Attributes

This element's attributes include the global attributes.

1. autoplay

A Boolean attribute: if specified, the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.

Note: Sites that automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, this can be useful when creating media elements whose source will be set at a later time, under user control.

2. controls

If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.

3. loop

A Boolean attribute: if specified, the audio player will automatically seek back to the start upon reaching the end of the audio.

4. muted

A Boolean attribute that indicates whether the audio will be initially silenced. Its default value is false.

so, here we see four types of attribute and mostly these are used in most of the cases. There are others also like preload and disableremoteplayback.

There are some events also which we can use but those are used when we make any music player project. Events are :-

  1. audioprocess:- The input buffer of a ScriptProcessorNode is ready to be processed.
  2. canplay :- The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
  3. canplaythrough :- The browser estimates it can play the media up to its end without stopping for content buffering.
  4. complete :- The rendering of an OfflineAudioContext is terminated.
  5. durationchange :- The duration attribute has been updated.
  6. emptied :- The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the HTMLMediaElement.load method is called to reload it.
  7. ended :- Playback has stopped because the end of the media was reached.
  8. loadeddata :- The first frame of the media has finished loading.
  9. loadedmetadata :- The metadata has been loaded.
  10. pause :- Playback has been paused.
  11. play :- Playback has begun.
  12. playing :- Playback is ready to start after having been paused or delayed due to lack of data.
  13. ratechange :- The playback rate has changed.
  14. seeked :- A seek operation completed.
  15. seeking :- A seek operation began.
  16. stalled :- The user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
  17. suspend :- Media data loading has been suspended.
  18. timeupdate :- The time indicated by the currentTime attribute has been updated.
  19. volumechange :- The volume has changed.
  20. waiting :- Playback has stopped because of a temporary lack of data.

OK, so in starting i told that we will talk about <source> so let's go :-

  • <source>- The HTML element specifies multiple media resources for the , the element, or the element. It is a void element, meaning that it has no content and does not have a closing tag.

Video Tag -

The tag is used to embed video content in a document, such as a movie clip or other video streams.

The tag contains one or more tags with different video sources. The browser will choose the first source it supports.

The text between the and tags will only be displayed in browsers that do not support the element.

It has also same attribute as <audio> tag such as :-

  1. autoplay
  2. controls
  3. loop
  4. muted
  5. height - By this attribute we can set the height of the video.
  6. width - By this attribute we can set the width of the video.