-
Notifications
You must be signed in to change notification settings - Fork 2
/
linear.html
64 lines (54 loc) · 1.42 KB
/
linear.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Linear Fade Demo</title>
<style>
.hidden {
display: none;
}
</style>
</head>
<body>
<div id='play' class='hidden'>Play</div>
<div id='stop'>Stop</div>
<script type="text/javascript">
(function(){
/*
Test script to demonstrate an exponential fade.
*/
var ctx = new AudioContext(),
url = 'Legend.mp3',
audio = new Audio(url),
gainNode = ctx.createGain(),
source,
start,
end,
play,
stop;
audio.addEventListener('canplaythrough', function(){
source = ctx.createMediaElementSource(audio);
source.connect(gainNode);
gainNode.connect(ctx.destination);
start = ctx.currentTime;
end = start + 5;
gainNode.gain.linearRampToValueAtTime(0.01, start);
gainNode.gain.linearRampToValueAtTime(1, end);
audio.play();
});
play = document.getElementById("play");
play.addEventListener('click', function(e){
play.className='hidden';
stop.className='';
audio.play();
})
stop = document.getElementById("stop");
stop.addEventListener('click', function(e){
play.className='';
stop.className='hidden';
audio.pause();
})
})();
</script>
</body>
</html>