更新时间:2023-02-13 23:38:09
这看起来并不像正确的方式使用的音频的构造函数HTMLAudioElement / <audio>$c$c>.
That doesn't look like the correct way to use the Audio constructor for HTMLAudioElement / <audio>
.
轻微的调整
var snd = new Audio("data:audio/wav;base64," + base64string);
snd.play();
如果它工作在控制台,但不是在脚本中,它可能会越来越垃圾回收,在这种情况下,范围它,所以它会留
If it works in console but not in script, it may be getting garbage collected, in which case scope it so it will stay
var Sound = (function () {
var df = document.createDocumentFragment();
return function Sound(src) {
var snd = new Audio(src);
df.appendChild(snd); // keep in fragment until finished playing
snd.addEventListener('ended', function () {df.removeChild(snd);});
snd.play();
return snd;
}
}());
// then do it
var snd = Sound("data:audio/wav;base64," + base64string);