且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

声音播放/停止/暂停

更新时间:2023-09-22 07:57:16

如果您进行了更改:

soundPlayer = new Audio(soundName).play();

为此:

soundPlayer = new Audio(soundName);
soundPlayer.play();

您的暂停将会起作用.问题是您为soundPlayer分配了播放"功能. SoundPlayer现在不是音频对象.

Your pause will be working. The problem is that you assigned "play" function to soundPlayer. SoundPlayer isnt an Audio object now.

代替stop()使用:

Instead of stop() use:

soundPlayer.pause();
soundPlayer.currentTime = 0;

它的工作原理与我猜想的一样.

It works the same I guess.