Trying to pause audio that is being played in brower

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

You should use the audio plugin

Can you please explain it in more detail

Sure, check this out

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