在Lollipop chrome中通过JS播放本地mp3文件

时间:2017-11-05 09:12:39

标签: javascript audio

我尝试通过JS播放本地mp3文件,这可以在桌面chrome中使用,而不是在android chrome中(示例中的文件当然不是本地文件)

play("https://www.soundjay.com/misc/bell-ringing-01.mp3");
 function play(h)
{
 a = new Audio(h);
 a.play(h);
}

更新:它适用于按钮调用,但不适用于将来的setTimeout播放调用

function start()
{
play("mp3/bell.mp3");
setTimeout("start();",3000);
}

<button onclick="start()">Start</button>

1 个答案:

答案 0 :(得分:0)

添加了


frequencyrank: no visible binding for global variable ‘data_m’

并在函数中

  <audio id="sound" ></audio>
  <button onclick="start()" style="font-size:300%;">Start</button>


 window.addEventListener('DOMContentLoaded', function(){
 audio = document.getElementById('sound');
 });