XMLHttpRequest :: audio加载失败

时间:2016-03-25 05:19:58

标签: javascript audio xmlhttprequest

我正在使用python SimpleHTTPServerlocalhost上投放测试页。

src标记的空audio

<audio id="audio" src=" "></audio>

请求:

<script>
var request = new XMLHttpRequest();
request.open("GET", "http://127.0.0.1:8000/audio/song.wav", true);
request.responseType = "blob";    
request.onload = function() {
  if (this.status == 200) {
    var audio = document.getElementById("audio");
    var src = URL.createObjectURL(this.response);
    audio.src = src;
    audio.load();
    audio.play();
  }
}
request.send();
</script>

XHR加载失败。错误在哪里?

0 个答案:

没有答案