I wrote

<embed src="mysound.mp3" controls="smallconsole" autostart="true" loop=3>

The "loop=3" never workes. It always plays just once. Replacing "loop=3" by "playcount=3" makes no difference. This is the same whether using IE or FireFox. What's the cause?

How to play it 3 times (i.e. more than once, but not infinite times)?

Dani AI

Generated

: The numeric loop=3 on an embed element is unreliable because embed is plugin/implementation dependent and there is no standard numeric loop attribute that browsers must support. 's loop="3" will hit the same limitation, and 's suggestion to check browser repeat settings is worth a quick look but usually not the root cause. See the embed notes and the audio element docs for how modern browsers handle looping and attributes: MDN: embed element and MDN: audio element — loop.

To play a sound a fixed number of times, use the HTML5 audio element and count playbacks in JavaScript. Attach the ended listener before starting playback so you can replay up to your target count:

<audio id="player" src="mysound.mp3"></audio>

<script>
var player = document.getElementById('player');
var maxPlays = 3;
var plays = 1;
player.addEventListener('ended', function () {
  if (plays < maxPlays) {
    plays++;
    player.play();
  }
});
player.play().catch(function () { /* autoplay blocked; let user start it */ });
</script>

Troubleshooting notes: test in the browser console for network or MIME-type errors (missing file or wrong Content-Type can stop playback). Modern browsers often block autoplay without user interaction — see the Autoplay guide. If targeting very old browsers or plugin players, vendor-specific object/embed parameters existed but are not portable; the HTML5 approach above is the most reliable cross-browser solution.

Recommended Answers

All 3 Replies

try: loop="3"

litchi, it's the same using loop="3".

Is repetition turned off in the browser settings?

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.