Pla">
无法让 Tone Player 播放任何内容,这是我的简单 VueJs 代码:
Simple Tone.js Demo
我正在加载的声音存在于正确的位置 sound/rain.wav 并且如果我在 chrome 中输入它的路径,浏览器能够正确打开它 http://localhost:5173/sounds/rain.wav
运行应用程序得到的输出:
了解 Tone.js 的人可以帮助我让播放器播放单个文件吗?我花了一整天的时间来解决这个问题,甚至使用了 GPT4,但我遇到了同样的问题,播放器无法播放简单的文件。
I guess the error occurred because
Playerhas not finished downloading the audio.The constructor does not return a promise. If you want to wait until the
Playeris ready, you need to pass theonloadfunction. By wrapping it in a Promise, it can be used to wait for thePlayerto be ready.this.player = await new Promise((resolve, reject) => { const player = new Tone.Player({ loop: true, onerror: (err) => reject(err), onload: () => resolve(player), url: '/sounds/rain.wav' }); }); this.player.toDestination();