我正在尝试通过拼凑示例来在线学习教程。我觉得这应该是播放 mp3 文件。我正在使用 Chrome 浏览器,它是最新的。我在控制台上没有任何错误。我不确定我需要更改或添加什么来完成这项工作。
<html>
<head>
<script type="text/javascript">
var context;
var sound1Buffer = null;
var url = 'https://dl.dropboxusercontent.com/u/1957768/SrtV2.mp3';
function init(){
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
}
catch(e) {
alert("web Audio api is not supported!");
}
}
window.addEventListener('load', init, false);
function loadDogSound(url){
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = 'arrayBuffer';
//decode asynchronously
request.onload = function(){
context.decodeAudioData(request.response, function(buffer){
sound1Buffer = buffer;
}, onError);
}
request.send();
}
function playSound(sound1Buffer){
var source = context.createBufferSource();
source.sound1Buffer = sound1Buffer;
source.connect(context.destination);
source.start(0);
}
</script>
</head>
<body>
</body>
</html>