# Trying to pause audio that is being played in brower

**URL:** <https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713>\
**Category:** Ask us anything\
**Created:** [September 9, 2024, 6:36am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713 "2024-09-09T06:36:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhruvi](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@Dhruvi](https://community.weweb.io/u/Dhruvi)\
**Post date:** [September 9, 2024, 6:36am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713/1 "2024-09-09T06:36:24Z")

</div>

function playCustomeRingtone(ringtonePath) {  
audioId.value = `audio-${Date.now()}`; // Generate a unique ID based on timestamp

```
// Find the existing audio element
let audioElement = document.getElementById(audioId.value);

if (!audioElement) {
    // If the audio element doesn't exist, create it
    audioElement = new Audio(ringtonePath);
    audioElement.id = audioId.value;
    document.body.appendChild(audioElement);
} else {
    // If it exists, update its source
    audioElement.src = ringtonePath;
}

audioElement.preload = "auto";

console.log('Audio element:', audioElement);

audioElement.onerror = () => {
    console.error("Failed to load audio. Falling back to default.");
    audioElement.src = ringtonePath;
    audioElement.play().catch(error => {
        console.error('Error playing the fallback audio:', error);
    });
};

// Play the audio
audioElement.play().then(() => {
    console.log('Playing audio with ID:', audioId.value);
}).catch(error => {
    console.error('Error playing the audio:', error);
});

return audioId.value;

```

}  
function stopRingtone() {  
const audioElement = document.getElementById(audioId.value);  
if (audioElement) {  
audioElement.pause();  
audioElement.currentTime = 0;  
setTimeout(() =\> {  
console.log(`Paused audio with ID: ${audioId.value}`);  
console.log(‘Audio paused state:’, audioElement.paused);  
console.log(‘Audio current time:’, audioElement.currentTime);  
}, 100);  
} else {  
console.error(`No audio found with ID: ${audioId.value}`);  
}  
}

i am trying to implemet custom ringtone, audio is getting played but not getting paused when stopRingtone() is called even though  
console.log(`Paused audio with ID: ${audioId.value}`);  
console.log(‘Audio paused state:’, audioElement.paused);  
console.log(‘Audio current time:’, audioElement.currentTime);  
is getting executed successfully

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [September 9, 2024, 7:37am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713/2 "2024-09-09T07:37:17Z")

</div>

You should use the audio plugin

---

<div class="post-metadata">

**Author:** ![Dhruvi](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@Dhruvi](https://community.weweb.io/u/Dhruvi)\
**Post date:** [September 9, 2024, 7:51am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713/3 "2024-09-09T07:51:29Z")

</div>

Can you please explain it in more detail

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [September 9, 2024, 8:26am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713/4 "2024-09-09T08:26:02Z")

</div>

Sure, check this out

> **[Sound | WeWeb Documentation](https://docs.weweb.io/plugins/extensions/sound.html)**
>
> Learn how to use the Sound plugin in Weweb

---

<div class="post-metadata">

**Author:** ![Dhruvi](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@Dhruvi](https://community.weweb.io/u/Dhruvi)\
**Post date:** [September 9, 2024, 8:53am UTC](https://community.weweb.io/t/trying-to-pause-audio-that-is-being-played-in-brower/10713/5 "2024-09-09T08:53:59Z")

</div>

that doesn’t help, audio still continues to play even after pausing it
