/
index.html
46 lines (46 loc) · 1.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>demo</title>
<style>
body{
padding: 40px;
}
</style>
<script src="../Bufferloader.js"></script>
<script type="text/javascript">
// 浏览器要求必须要用户交互后才能播放音频
const loadAndPlay = async () => {
let context = new AudioContext();
const bufferList = await BufferLoader(context, ['../test1.mp3', '../test2.mp3']);
let source1 = context.createBufferSource();
let 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>
</head>
<body>
<h2>第一章 demo</h2>
<button onclick="loadAndPlay()">加载并播放</button>
<hr/>
<dl>
<dt style="color: red;">注意:</dt>
<dd>需要在服务器环境下测试</dd>
<dd>可安装 https://www.npmjs.com/package/serve</dd>
<dd>全局安装 serve 后 到 example 目录运行 "serve ." 即可启动本地服务</dd>
<dd>浏览器不允许主动播放音视频,需要用户交互后才可以</dd>
</dl>
<dl>
<dt style="color: red;">注意:</dt>
<dd>测试音频并不代表我的音乐喜好</dd>
<dd>如有侵权请联系我</dd>
</dl>
</body>
</html>