我正在开发一个健全的JavaScript库.我可以用下面的代码播放声音.
var soundPlayer = null;
function playSound(){
soundPlayer = new Audio(soundName).play();
}
Run Code Online (Sandbox Code Playgroud)
如何停止和暂停此音频?当我尝试这样的时候:
soundPlayer.pause();
Run Code Online (Sandbox Code Playgroud)
要么
soundPlayer.stop();
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
Uncaught TypeError: soundPlayer.stop is not a function
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?