Translate

New Live Courses

🚀 *Gen AI Engineer Telugu (Production Focused)*
🗓️ *Date:* 30th Sept 2026, 07:00AM IST
📝 *Register Now!:*
https://www.vlrt.in/gr
👥 *Join WA Community:*
https://www.vlrt.in/gw
💡*Course Content:*
https://www.vlrt.in/ai
▶️ *Demo Videos:*
https://www.vlrt.in/gv

🚀 *Service now Admin/ Development (ITSM)FREE Demo in Telugu*
🗓️ *Date:* 30th Sept 2026, 08:00AM IST
📝 *Register Now!:*
https://www.vlrt.in/7r
👥 *Join WA Community:*
https://www.vlrt.in/7w
💡*Course Content:*
https://www.vlrt.in/7c
▶️ *Demo Videos:*
https://www.vlrt.in/7v

🚀 *Vulnerability Management Training Demo*
🗓️ *Date:* 30th Sept 2026, 09:00 AM IST
📝*Register Now!:*
https://www.vlrt.in/vr
👥 *Join Community:*
https://www.vlrt.in/cw
💡 *Course Content:*
https://www.vlrt.in/vc
▶️ *Demo Videos:*
https://www.vlrt.in/Vm

Wednesday, 31 January 2024

How to embed Audio element in HTML? 042

 How to embed Audio element in HTML?


You can embed audio in HTML using the <audio> element, providing a standardized way to include sound on your web pages. Here's the basic structure:


HTML

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

Explanation:

  • The <audio> element defines the audio container.

  • The controls attribute adds playback controls like play, pause, volume, etc.

  • Similar to video embedding, you can include one or more <source> elements within the <audio> tag.

  • Each <source> element specifies a different audio source file.

  • The src attribute defines the path to the audio file.

  • The type attribute specifies the MIME type of the audio format (e.g., audio/mpeg, audio/ogg).

Why multiple source elements?

Similar to video embedding, using multiple <source> elements offers two key benefits:

  1. Browser compatibility: Different browsers support different audio formats. Providing multiple sources with various formats increases accessibility for users across different browsers.

  2. Adaptive bitrate streaming: Modern browsers can adjust audio quality based on the user's internet connection speed. Offering sources with different bitrates allows the browser to choose the optimal version for a smooth listening experience.

Additional notes:

  • You can use the autoplay attribute on the <audio> element to start playing the audio automatically when the page loads. However, use this cautiously as it might disrupt user experience.

  • The <audio> element also supports features like captions and a looping attribute to repeat playback continuously.

  • Consider using audio hosting platforms like SoundCloud or Buzzsprout for easier embedding and management.

By effectively using the <audio> element and incorporating multiple <source> elements, you can create accessible and engaging audio experiences on your web pages, catering to a wider audience with diverse browser and connection conditions.

Sources

1. https://github.com/aneta-s/LOCDOWN


No comments:

Post a Comment

Note: only a member of this blog may post a comment.