While I've been using the javascript media promise to identify when autoplay has failed according to this guide: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes, I'm curious about how to detect an autoplay failure in WaveSurfer.js.
Despite attempting to use the error event, it doesn't seem to be effective in this scenario. Additionally, the play event consistently triggers regardless of whether the audio is actually playing or not.
https://jsfiddle.net/mcrockett/k985zjh2/18/
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'red',
progressColor: 'purple'
});
function play() {
wavesurfer.playPause();
}
wavesurfer.on('ready', play);
wavesurfer.on('error', function(){
console.log("does not get called when autoplay fails :(");
});
wavesurfer.on('play', function(){
console.log("called even when autoplay fails");
});
wavesurfer.load('https://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');
Check out my jsfiddle for a demonstration. In Google Chrome, autoplay typically encounters failures.