JavaScript - 如何停止正在运行的音频?

时间:2015-02-25 17:48:57

标签: javascript google-chrome html5-audio

如何在需要时停止此循环音频? (它一直在谷歌Chrome稳定,金丝雀测试中继续玩)

var song = null;
function a() {
  song = new Audio("audio/ring.wav");
  song.controls = false;
  song.loop = true;
  song.autoplay = true;
  document.body.appendChild(song);
}  

a();

1 个答案:

答案 0 :(得分:1)

var song = null;

function a() {
  song = new Audio("audio/ring.wav");
  song.controls = false;
  song.loop = true;
  song.autoplay = true;
  document.body.appendChild(song);
}  

a();

// Pause the audio, please note there is no stop event
song.pause();