-
Notifications
You must be signed in to change notification settings - Fork 19
/
example_7.html
91 lines (85 loc) · 3.21 KB
/
example_7.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<title>Example 8</title>
</head>
<body>
<a href="./index.html"> << back</a>
<div class="center-align">
<h1>Example 7 - <span>Version_8 </span></h1>
<p>getUserMedia() - AudioContext() - createMediaStreamSource() - createBiquadFilter()</p>
<br>
<button class="btn waves-effect waves-light js-start">Start</button>
<button class="btn waves-effect waves-light js-stop" disabled>Stop</button>
<br>
<br>
<button class="btn waves-effect waves-light js-code">Show Code</button>
</div>
<hr>
<pre style="font-family: GillSans, Calibri, Trebuchet, sans-serif;" class="hide"></pre>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<script class="containerScript">
if (navigator.mediaDevices) {
console.log('getUserMedia supported.');
} else {
console.log('getUserMedia not supported on your browser!');
}
let startBtn = document.querySelector('.js-start');
let stopBtn = document.querySelector('.js-stop');
let codeBtn = document.querySelector('.js-code');
let pre = document.querySelector('pre');
let freqResponseOutput = document.querySelector('.freq-response-output');
let audioCtx;
let track;
/**
* getUserMedia block - grab stream put it into a MediaStreamAudioSourceNode
* also output the sound into a audio element
*/
startBtn.addEventListener('click', () => {
navigator.mediaDevices.getUserMedia ({audio: true, video: false})
.then(function(stream) {
startBtn.setAttribute('disabled', true);
stopBtn.removeAttribute('disabled');
/**
* Create a MediaStreamAudioSourceNode Feed the HTMLMediaElement into it
*/
window.AudioContext = window.AudioContext || window.webkitAudioContext;
audioCtx = new AudioContext();
track = stream.getTracks()[0];
let source = audioCtx.createMediaStreamSource(stream);
/**
*Create a biquadfilter
*/
let biquadFilter = audioCtx.createBiquadFilter();
biquadFilter.type = "lowshelf";
biquadFilter.frequency.value = 1000;
/**
* biquadFilter.gain.value = range.value; connect the AudioBufferSourceNode to the
* gainNode and the gainNode to the destination, so we can play the music and adjust
* the volume using the mouse cursor
*/
source.connect(biquadFilter);
biquadFilter.connect(audioCtx.destination);
})
.catch(function(err) {
console.log('The following gUM error occured: ' + err);
});
});
stopBtn.addEventListener('click', () => {
startBtn.removeAttribute('disabled');
stopBtn.setAttribute('disabled', true);
track.stop();
});
codeBtn.addEventListener('click', () => {
pre.classList.toggle('hide');
pre.innerHTML = document.querySelector('.containerScript').innerHTML;
});
</script>
</body>
</html>