I am trying to play an audio and generating it's waveform using Wavesurfer.js, however when I click the Play button, an AudioContext warning gets displayed in the console and the audio does not play. This issue is weird in a way, because it does not happen all the time but seems to occur randomly.
Code (HTML):
<button type="button" id="btn-playpause" title="Play or pause the audio.">
<img src="playpause.svg" alt="SVG image" width="25px" height="25px">
</button>
Code (Javascript):
const playButton = document.getElementById("btn-playpause");
playButton.addEventListener('click', () => {
wavesurfer.playPause();
console.log("Clicked Play/Pause");
})
I have also tried this, it gives the same error:
const playButton = document.getElementById("btn-playpause");
playButton.addEventListener('click', () => {
console.log("Clicked Play/Pause");
if (wavesurfer.isPlaying()){
wavesurfer.pause();
}
else{
wavesurfer.play();
}
})
Please do let me know some fixes if possible, thanks.