I have created a custom play/pause button in HTML (with the class 'play-pause'). When the button is clicked, it toggles playing and pausing an audio file. The entire script looks like this:
var audio = new Audio('https://www.dropbox.com/s/wsdf7dwg7yrs0hs/Angels-Robbie-Williams%20%281%29.mp3?dl=1');
$('.play-pause').on('click', function() {
if(audio.paused) {
audio.play();
}
else {
audio.pause();
}
});
It works perfectly in Chrome. But in Safari, nothing happens when the toggle button is pressed (can't get the audio to play at all) – and the console outputs this:
' Unhandled Promise Rejection: AbortError: The operation was aborted.'
Any suggestions how to make the audio play/pause in Safari?