-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathmulti-audios-recording.html
95 lines (73 loc) · 2.65 KB
/
multi-audios-recording.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
<style>
html, body, video, canvas {
margin: 0!important;
padding: 0!important;
}
audio { vertical-align: middle; }
</style>
<title>Multiple Audios Recording using RecordRTC</title>
<h1>Multiple Audios Recording using RecordRTC</h1>
<br>
<button id="btn-enable-microphone">Enable Microphone</button>
<button id="btn-start-recording" disabled>Start Recording</button>
<button id="btn-stop-recording" disabled>Stop Recording</button>
<hr>
(First Microphone) <audio id="audio-1" controls autoplay playsinline></audio>
<hr>
(Second Microphone) <audio id="audio-2" controls autoplay playsinline></audio>
<script src="/RecordRTC.js"></script>
<script>
var audio1 = document.querySelector('#audio-1');
var audio2 = document.querySelector('#audio-2');
function captureMicrophone(callback) {
navigator.mediaDevices.getUserMedia({ audio: true }).then(function(microphone) {
callback(microphone);
}).catch(function(error) {
alert('Unable to capture your microphone. Please check console logs.');
console.error(error);
});
}
function stopRecordingCallback() {
audio1.srcObject = null;
audio2.srcObject = null;
var blob1 = recorder1.getBlob();
audio1.src = URL.createObjectURL(blob1);
var blob2 = recorder2.getBlob();
audio2.src = URL.createObjectURL(blob2);
document.getElementById('btn-start-recording').disabled = false;
}
var recorder1, recorder2; // globally accessible
document.getElementById('btn-enable-microphone').onclick = function() {
this.disabled = true;
captureMicrophone(function(microphone) {
recorder1 = RecordRTC(microphone, {
type: 'audio'
});
recorder2 = RecordRTC(microphone, {
type: 'audio'
});
recorder1.microphone = microphone;
recorder2.microphone = microphone;
document.getElementById('btn-start-recording').disabled = false;
audio1.srcObject = recorder1.microphone;
});
};
document.getElementById('btn-start-recording').onclick = function() {
this.disabled = true;
audio1.srcObject = recorder1.microphone;
audio2.srcObject = recorder2.microphone;
recorder1.startRecording();
recorder2.startRecording();
document.getElementById('btn-stop-recording').disabled = false;
};
document.getElementById('btn-stop-recording').onclick = function() {
this.disabled = true;
recorder1.stopRecording(function() {
recorder2.stopRecording(function() {
stopRecordingCallback();
});
});
};
</script>
<footer style="margin-top: 20px;"><small id="send-message"></small></footer>
<script src="https://www.webrtc-experiment.com/common.js"></script>