做项目的时候出现的问题:The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
看这个意思是说必须要用户手动进行一个操作,才能启用音频的相关功能,不能一打开就自动调用,
查到的解决帖子:参考1 参考2
帖子中也是说要进行手动操作,比如加个btn,手动点击的时候就调用,然后再进行自己的项目想要的操作
在github上有一个解决方法 https://github.com/Tonejs/Tone.js/issues/341
所以我只要在index入口处,加上监听mousedown,一按下就给context.resume了就行
document.documentElement.addEventListener('mousedown', () => {
if (Tone.context.state !== 'running')
Tone.context.resume();
});```
这样问题就解决了,虽然依旧会有警告,但是不影响