-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
82 lines (70 loc) · 2 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Playground</title>
</head>
<body>
<audio
is="modern-audio"
src="./test/assets/audio.mp3"
controls
pan="0"
fade-in="3"
fade-out="3"
>
</audio>
<div style="margin-bottom: 10px;">
<button id="play">Play</button>
</div>
<div style="margin-bottom: 10px;">
<button id="download">Download</button>
</div>
<div style="margin-bottom: 10px;">
<button id="time-domain-bar-chart">TimeDomainBarChart</button>
</div>
<div style="margin-bottom: 10px;">
<button id="bar-chart">BarChart</button>
</div>
<div style="margin-bottom: 10px;">
<canvas id="time-domain-bar-chart-canvas"></canvas>
</div>
<div style="margin-bottom: 10px;">
<canvas id="bar-chart-canvas"></canvas>
</div>
<script type="module">
import { ModernAudio } from './src'
ModernAudio.install()
</script>
<script type="module" async>
import { createAudio, createOfflineAudioContext, downloadOfflineAudio } from './src'
const audio = await createAudio('./test/assets/audio.mp3')
await audio.load()
audio.set({
playbackRate: 1.2,
})
document.querySelector('#play').onclick = (e) => {
const el = e.target
const isPlaying = el.dataset.playing === 'true'
el.dataset.playing = !isPlaying
if (isPlaying) {
el.innerHTML = 'Play'
audio.reset()
} else {
el.innerHTML = 'Pause'
audio.start(0, audio.context.currentTime)
}
}
document.querySelector('#bar-chart').onclick = () => audio.renderBarChart(document.querySelector('#bar-chart-canvas'))
document.querySelector('#time-domain-bar-chart').onclick = () => audio.renderTimeDomainBarChart(document.querySelector('#time-domain-bar-chart-canvas'))
const context = createOfflineAudioContext(10)
const offlineAudio = createAudio('./test/assets/audio.mp3', context)
await offlineAudio.load()
offlineAudio.set('playbackRate', 2)
document.querySelector('#download').onclick = () => {
offlineAudio.start()
downloadOfflineAudio(context)
}
</script>
</body>
</html>