-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_5.html
76 lines (67 loc) · 2.71 KB
/
example_5.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
<!DOCTYPE html>
<html>
<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">
<script src="https://webrtcexperiment-webrtc.netdna-ssl.com/RecordRTC.js"></script>
<title>Document</title>
</head>
<body>
<a href="./index.html"> << back</a>
<div class="center-align">
<h1>Example 5 - <span>Version_8 </span></h1>
<p>getUserMedia() - <a href="https://webrtcexperiment-webrtc.netdna-ssl.com/RecordRTC.js">RecordRTC</a> </p>
<audio controls></audio>
<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">
let audioStream;
let startBtn = document.querySelector('.js-start');
let stopBtn = document.querySelector('.js-stop');
let recordRTC;
let pre = document.querySelector('pre');
let codeBtn = document.querySelector('.js-code');
let record = function(audioStream) {
console.log('Recordin...');
startBtn.setAttribute('disabled', true);
stopBtn.removeAttribute('disabled');
recordRTC = RecordRTC(audioStream, {recorderType: StereoAudioRecorder});
recordRTC.startRecording();
}
function errorCallback(error) {
console.log('maybe another application is using the device');
}
startBtn.addEventListener('click', () => {
navigator.mediaDevices.getUserMedia({audio: true, video: false}).then(record).catch(errorCallback); /** ask permission of the user for use microphone or camera */
});
stopBtn.addEventListener('click', () => {
console.log('Stop Recordin...');
stopBtn.setAttribute('disabled', true);
startBtn.removeAttribute('disabled');
recordRTC.stopRecording(function(audioURL) {
let recordedBlob = recordRTC.getBlob();
recordRTC.getDataURL(function(dataURL) {
let audio = document.querySelector('audio');
audio.src = dataURL;
});
});
});
codeBtn.addEventListener('click', () => {
pre.classList.toggle('hide');
pre.innerHTML = document.querySelector('.containerScript').innerHTML;
});
</script>
</body>
</html>