替换typescript中的set timeout.Wavesurfer.js



我有一个函数,在这里我改变了wavesurfer.js音频文件的源,然后想用新加载的音频文件播放歌曲。目前,我的代码按照我想要的方式运行,但我觉得必须有更好的方法来做到这一点。

这是我的功能。

changeAudioFile(i){
let newSong = 'Link to a different File'
this.ws.load(newSong);
setTimeout(() => {
this.ws.play()
}, 1000);
}

可以监听ready事件

this.ws.on('ready',() => {
this.ws.play()
});

文档

最新更新