I use a WYSIWYG tool to design my web pages, I want to change the part that handles sound to html5 so it will work better on another platform I want to use.

I have looked at the code my editor made, this looks like the bit that needs changing to me, I think its all there, all my web pages use the same technique/code to add sound, the only variant is that some use looping sound for some pages, so that also needs to be in mind.

<embed id = backmusic src="./media/explosion.wav" autostart="true" width="1" height="1" loop="false"></embed>
<noembed> <bgsound src="./media/explosion.wav" loop=false> </noembed>

Could someone show me what the code be if this was html5?
Thank you for help offered.

Dani AI

Generated

Quick summary: was right to point toward the HTML5 <audio> element; ’s old <embed>/<bgsound> approach is obsolete. The problem in the thread is purely syntax: an extra > and putting loop in the wrong place will break the element. Use the audio tag with boolean attributes inside the opening tag and provide multiple source formats for broader support.

A simple, correct pattern (replace filenames) — note loop and autoplay appear inside the opening tag and you can include multiple <source> entries for fallbacks:

<audio id="bgAudio" autoplay loop preload="auto">
  <source src="media/background.mp3" type="audio/mpeg">
  <source src="media/background.ogg" type="audio/ogg">
  Fallback text for very old browsers.
</audio>

If you need a programmatic fallback for looping (older or quirky players), handle the ended event and restart playback:

<script>
  var a = document.getElementById('bgAudio');
  if (a) {
    a.addEventListener('ended', function(){ this.currentTime = 0; this.play(); }, false);
  }
</script>

Troubleshooting checklist (common causes seen in this thread)

  • Remove stray characters (extra >).
  • Put loop and autoplay inside the opening tag (they are boolean attributes).
  • Verify file paths and server MIME types (audio/mpeg, audio/ogg).
  • Add controls while testing so you can play/pause manually.
  • For background music vs. short effects: use background audio for ambient loops and trigger short effects via JS for user interactions.

Caveat: some browsers/phones limit autoplay with sound; if autoplay fails, offer controls or start muted and unmute on user interaction.

Recommended Answers

All 4 Replies

<audio src="source of file" autoplay>

    Non html5 here

</audio>

I believe that is the syntax

Thank you for your answer
So do I put

<noembed> <bgsound src="./media/explosion.wav" loop=false> </noembed>

where you have it marked at
3. Non html5 here
That way I can say if its looped or not? Strange, I thought the code for looping or just playing once would also be written in html5 as well.

this works but the looping doesnt work

<audio controls="controls" autoplay="autoplay"> loop="loop">
<source src="./media/explosion.wav" type="audio/wav" />
</audio>

Look at your syntax. You included an extra >.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.