-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathoverview-waveform.html
144 lines (128 loc) · 4.63 KB
/
overview-waveform.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Peaks.js Demo Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
#overview-container {
height: 200px;
}
</style>
</head>
<body>
<div id="titles">
<h1>Peaks.js</h1>
<p>
Peaks.js is a JavaScript library that allows you to display and
interact with audio waveforms in the browser.
</p>
<h2>Demo pages</h2>
<p>
The following pages demonstrate various configuration options:
</p>
<p>
<a href="/index.html">Precomputed Waveform Data</a> |
<a href="/webaudio.html">Web Audio API</a> |
<a href="/zoomable-waveform.html">Single Zoomable Waveform</a> |
Single Fixed Waveform |
<a href="/cue-events.html">Cue Events</a> |
<a href="/set-source.html">Changing the Media URL</a> |
<a href="/multi-channel.html">Multi-Channel Waveform</a> |
<a href="/custom-markers">Custom Point and Segment Markers</a> |
<a href="/overlay-segments.html">Overlay Segments</a> |
<a href="/external-player.html">External Audio Player</a> |
<a href="/scrollbar.html">Scrollbar</a>
</p>
<h2>Demo: Single Fixed Waveform</h2>
<p>
This demo shows how to configure Peaks.js to render a single waveform
view, scaled to fit a given container element.
</p>
</div>
<div class="waveform-container">
<div id="overview-container"></div>
</div>
<div id="demo-controls">
<audio id="audio" controls="controls">
<source src="/TOL_6min_720p_download.mp3" type="audio/mpeg">
<source src="/TOL_6min_720p_download.ogg" type='audio/ogg; codecs="vorbis"'>
Your browser does not support the audio element.
</audio>
<div id="controls">
<div>
<input type="text" id="seek-time" value="0.0">
<button data-action="seek">Seek</button>
<label for="amplitude-scale">Amplitude scale</label>
<input type="range" id="amplitude-scale" min="0" max="10" step="1">
</div>
<div>
<label for="waveform-color">Waveform color</label>
<input type="color" id="waveform-color" value="#cccccc">
<label for="played-waveform-color">Played waveform color</label>
<input type="color" id="played-waveform-color" value="#888888">
</div>
</div>
</div>
<script src="/peaks.js"></script>
<script>
(function(Peaks) {
var options = {
overview: {
container: document.getElementById('overview-container'),
waveformColor: '#cccccc',
playedWaveformColor: '#888888',
showPlayheadTime: true
},
mediaElement: document.getElementById('audio'),
dataUri: {
arraybuffer: '/TOL_6min_720p_download.dat',
json: '/TOL_6min_720p_download.json'
},
keyboard: true
};
Peaks.init(options, function(err, peaksInstance) {
if (err) {
console.error(err.message);
return;
}
console.log('Peaks instance ready');
document.querySelector('button[data-action="seek"]').addEventListener('click', function(event) {
var time = document.getElementById('seek-time').value;
var seconds = parseFloat(time);
if (!Number.isNaN(seconds)) {
peaksInstance.player.seek(seconds);
}
});
var amplitudeScales = {
"0": 0.0,
"1": 0.1,
"2": 0.25,
"3": 0.5,
"4": 0.75,
"5": 1.0,
"6": 1.5,
"7": 2.0,
"8": 3.0,
"9": 4.0,
"10": 5.0
};
document.getElementById('amplitude-scale').addEventListener('input', function(event) {
var scale = amplitudeScales[event.target.value];
var view = peaksInstance.views.getView();
view.setAmplitudeScale(scale);
});
document.getElementById('waveform-color').addEventListener('input', function(event) {
var view = peaksInstance.views.getView();
view.setWaveformColor(event.target.value);
});
document.getElementById('played-waveform-color').addEventListener('input', function(event) {
var view = peaksInstance.views.getView();
view.setPlayedWaveformColor(event.target.value);
});
});
})(peaks);
</script>
</body>
</html>