# Is there a way to have an audio component play only once?

**URL:** https://forums.realmacsoftware.com/t/is-there-a-way-to-have-an-audio-component-play-only-once/57707
**Category:** Elements
**Tags:** elements
**Created:** [September 24, 2026, 10:29pm UTC](https://forums.realmacsoftware.com/t/is-there-a-way-to-have-an-audio-component-play-only-once/57707 "2026-09-24T22:29:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![warrengentry](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@warrengentry](https://forums.realmacsoftware.com/u/warrengentry)
#### Post date: [September 24, 2026, 10:29pm UTC](https://forums.realmacsoftware.com/t/is-there-a-way-to-have-an-audio-component-play-only-once/57707/1 "2026-09-24T22:29:42Z")

</div>

I would like for my audio component to play once and not restart. I don’t see a setting in the component that allows me to choose that option. Is there another way to achieve this?

---

<div class="post-metadata">

### Author: ![differentdan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/differentdan/32/33530_2.png) [@differentdan](https://forums.realmacsoftware.com/u/differentdan)
#### Post date: [September 24, 2026, 11:30pm UTC](https://forums.realmacsoftware.com/t/is-there-a-way-to-have-an-audio-component-play-only-once/57707/2 "2026-09-24T23:30:04Z")

</div>

Hi @warrengentry,

I’ve checked into this for you.

The audio itself is fine, but the Audio component is currently treating the end of the track as a signal to play the next track. Because there is only one audio file in the component, it ends up starting that same track again, which is why it keeps looping.

For now, you can copy some custom code into the page in Elements that tells the audio player to stop once that track reaches the end. This doesn’t change the audio file itself and only affects this particular track.

```javascript
<script>
document.addEventListener('ended', function (event) {
    if (
        event.target instanceof HTMLAudioElement &&
        event.target.src.endsWith('/audio-4-tradesmen.mp3')
    ) {
        event.stopImmediatePropagation();
    }
}, true);
</script>

```

 ![javascript-to-stop-audio-looping](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/4/f/4ff7e9347820f7b5f896263a900cf0554d2bf243.jpeg)

The audio should now play through once and then stop normally.

Republish your site once you get that code added and give it a try. Let us know how you get on.
