1
我想通過拼湊示例在線跟隨教程。我覺得這應該是播放MP3文件。我使用的是Chrome瀏覽器,並且它是最新的。我沒有在控制檯上發現任何錯誤。我不確定我需要更改或添加這項工作。基本的Web音頻API不播放聲音
<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>
功能'的init()'沒有問題,如果運行的瀏覽器不支持音頻API。這讓我覺得所有的函數在加載到瀏覽器時都會運行。我必須改變'window.addEventListener'中的內容嗎?什麼是調用'loadDogSound'和'playSound'的正確方法。原諒我,但我對這個東西還很陌生。 – oxxi
嘿,我喜歡搞亂網絡音頻API。我可以幫你嗎?我們聊聊吧? - http://chat.stackoverflow.com/rooms/32365/room-for-uber5001-and-oxxi – uber5001