forked from muaz-khan/RecordRTC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonStateChanged.html
92 lines (72 loc) · 2.5 KB
/
onStateChanged.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
<style>
html, body, video, canvas {
margin: 0!important;
padding: 0!important;
}
</style>
<title>onStateChanged using RecordRTC</title>
<h1>onStateChanged using RecordRTC</h1>
<br>
<label>State preview: </label>
<span id="state-preview" style="color: red;">inactive</span>
<button id="btn-start-recording">Start Recording</button>
<button id="btn-stop-recording" disabled>Stop Recording</button>
<button id="btn-pause-recording" disabled>Pause Recording</button>
<hr>
<video controls autoplay playsinline></video>
<script src="/RecordRTC.js"></script>
<script>
var video = document.querySelector('video');
function captureCamera(callback) {
navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then(function(camera) {
callback(camera);
}).catch(function(error) {
alert('Unable to capture your camera. Please check console logs.');
console.error(error);
});
}
function stopRecordingCallback() {
video.srcObject = null;
var blob = recorder.getBlob();
video.src = URL.createObjectURL(blob);
recorder.camera.stop();
}
var recorder; // globally accessible
document.getElementById('btn-start-recording').onclick = function() {
this.disabled = true;
captureCamera(function(camera) {
video.srcObject = camera;
recorder = RecordRTC(camera, {
type: 'video'
});
recorder.onStateChanged = function(state) {
document.getElementById('state-preview').innerHTML = state;
};
recorder.startRecording();
// release camera on stopRecording
recorder.camera = camera;
document.getElementById('btn-stop-recording').disabled = false;
document.getElementById('btn-pause-recording').disabled = false;
});
};
document.getElementById('btn-stop-recording').onclick = function() {
this.disabled = true;
recorder.stopRecording(stopRecordingCallback);
};
document.getElementById('btn-pause-recording').onclick = function() {
this.disabled = true;
if(this.innerHTML === 'Pause Recording') {
recorder.pauseRecording();
this.innerHTML = 'Resume Recording';
}
else {
recorder.resumeRecording();
this.innerHTML = 'Pause Recording';
}
setTimeout(function() {
document.getElementById('btn-pause-recording').disabled = false;
}, 2000);
};
</script>
<footer style="margin-top: 20px;"><small id="send-message"></small></footer>
<script src="https://www.webrtc-experiment.com/common.js"></script>