我是tone.js 的新手,我只想要一个简单的暂停按钮。我知道有一个 stop() 和 start() 但它不是暂停,何时再次开始音乐只是转到歌曲的开头。
我使用tone.js 是因为我想操纵音乐并进行一些合成声音。我也使用 p5.js 但不知何故暂停不起作用。它抛出一个错误,说“无法读取未定义的属性‘长度’。所以我想使用tone.js,但只需要弄清楚如何暂停音乐。谢谢。
这是代码
var player = new Tone.Player("data/audio/singingbird_audio.mp3").toMaster();
var whale = new Tone.Player("data/audio/whale.mp3").toMaster();
whale.autostart = false;
whale.volume.value = -10;
player.autostart = false;
player.volume.value = 5;
player.stop();
button = createButton('Play Bird');
button.position(20, 200);
button.mousePressed(birdSwitch);
function birdSwitch() {
if (player.state == "started") {
player.stop();
whale.stop();
} else if (player.state == "stopped") {
player.start();
whale.start();
}
}
Run Code Online (Sandbox Code Playgroud)