audio
HTML5 introduced the <audio> element for embedding audio content in web pages. With the <audio> element, you can play audio files such as MP3, WAV, and OGG files on your web pages.
Here is an example of how to use the <audio> element in HTML:
<audio controls> <source src="audiofile.mp3" type="audio/mpeg"> <source src="audiofile.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio>
In this example, we use the controls attribute to display a set of controls for the audio element, such as play, pause, and volume. We also provide two sources for the audio file, in MP3 and OGG formats, to ensure that it can be played on different browsers. The text "Your browser does not support the audio element." will be displayed if the browser does not support the <audio> element.
You can also add other attributes to the <audio> element to customize the playback, such as autoplay, loop, preload, and muted. For example, you can use autoplay to start playing the audio file automatically when the page is loaded, or loop to repeat the audio file continuously.
<audio controls autoplay loop> <source src="audiofile.mp3" type="audio/mpeg"> <source src="audiofile.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio>
In addition to the basic usage of the <audio> element, you can also use JavaScript to control the playback of the audio file, such as changing the volume, pausing and resuming the playback, and seeking to a specific position.
video
The <video> element is used to embed videos in an HTML document. The <video> element has a number of attributes that can be used to control the playback of the video, including the src attribute, which specifies the URL of the video file, and the controls attribute, which specifies whether to display video controls such as play/pause, volume, and full screen.
Here's an example of how to use the <video> element:
<video src="video.mp4" controls> Your browser does not support the video tag. </video>
In the example above, the src attribute specifies the URL of the video file (video.mp4). The controls attribute is set to display the video controls. If the browser does not support the <video> element, the text "Your browser does not support the video tag." will be displayed instead.
The <video> element also supports a number of other attributes, such as autoplay to automatically start playing the video, loop to loop the video playback, and poster to specify an image to display before the video starts playing.
You can also use the <source> element to specify multiple video files with different formats and resolutions, allowing the browser to choose the appropriate file to play based on the user's device and browser capabilities. Here's an example:
<video controls> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> Your browser does not support the video tag. </video>
In the example above, two video files with different formats are specified using the <source> element. The browser will choose the appropriate file to play based on its capabilities. If neither format is supported, the text "Your browser does not support the video tag." will be displayed.

Comments
Post a Comment