网络音频api不会播放声音

时间:2015-06-07 12:50:22

标签: javascript audio web

pls guys im stock我需要帮助这些我一直得到错误,bufferlist undefined,loadDogSound undefined.if不会得到任何错误它不会播放。

提前谢谢。



<script>
window.onload = init;
var context;
var bufferLoader;

function init() {
  // Fix up prefixing
  window.AudioContext = window.AudioContext || window.webkitAudioContext;
  context = new AudioContext();

  bufferLoader = new BufferLoader(
    context,
    [
      'audio/b.mp3',
      'audio/a.mp3',
    ],
    finishedLoading
    );

  bufferLoader.load();
}

function finishedLoading(bufferList) {
	context = new AudioContext();
  // Create two sources and play them both together.
  var source1 = context.createBufferSource();
  var source2 = context.createBufferSource();
  source1.buffer = bufferList[0];
  source2.buffer = bufferList[1];

  source1.connect(context.destination);
  source2.connect(context.destination);
  source1.start(0);
  source2.start(0);
}

</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试创建一个引用此页面上讨论的对象的脚本:http://middleearmedia.com/web-audio-api-bufferloader/

根据说明你应该创建一个名为buffer-loader.js的文件,并将以下行放在你的html文件的头部:

<script type="text/javascript" src="buffer-loader.js"></script>

以下是您方便使用的文件的贴纸:http://pastie.org/10227922

当我添加此文件时,您的示例可以正常运行。

相关问题