在Dart中工作音频循环示例

时间:2016-02-04 20:05:57

标签: dart dart-html

我正在尝试使用Dart使用HTML5 <audio>元素来循环获取OGG文件。有没有人有这方面的工作实例。我特别难以让音频循环播放。

1 个答案:

答案 0 :(得分:1)

我无法使用html5 AudioElement完全控制循环;有时循环选项根本不起作用,有时会出现间隙,有时模式会重叠。

我有更好的机会使用WebAudio,比如:

source = audioContext.createBufferSource();
source.buffer = buffer;

gainNode = audioContext.createGain();
gainNode.gain.value = 1;

source.connectNode(gainNode);
gainNode.connectNode(audioContext.destination);

// play it now in loop
source.start(audioContext.currentTime);
source.loop = true;

我无法从html音频元素加载源缓冲区,这可能是我遇到的CORS问题的解决方案。使用http请求加载样本。

我创建了一个dartpad示例,演示了使用AudioElement本机循环功能和WebAudio

的循环

https://dartpad.dartlang.org/879424bca794c63698b0