Permalink
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (51 sloc) 1.75 KB
<style>
html, body {
margin: 0!important;
padding: 0!important;
}
</style>
<title>pass getUserMedia constraints to RecordRTC</title>
<h1>pass getUserMedia constraints to RecordRTC</h1>
<br>
<button id="btn-start-recording">Start Recording</button>
<button id="btn-stop-recording" disabled>Stop Recording</button>
<hr>
<video controls autoplay></video>
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script>
var video = document.querySelector('video');
function stopRecordingCallback() {
video.src = video.srcObject = null;
video.src = URL.createObjectURL(recorder.getBlob());
video.play();
recorder.camera.stop();
recorder.destroy();
recorder = null;
}
var recorder; // globally accessible
document.getElementById('btn-start-recording').onclick = function() {
this.disabled = true;
// Example snippet
var constraints = {
video: { width: 360, height: 240 },
audio: true,
// recorderType: WhammyRecorder
};
navigator.mediaDevices.getUserMedia(constraints).then(function(camera) {
setSrcObject(camera, video);
video.play();
recorder = RecordRTC(camera, constraints);
recorder.startRecording();
// release camera on stopRecording
recorder.camera = camera;
document.getElementById('btn-stop-recording').disabled = false;
});
};
document.getElementById('btn-stop-recording').onclick = function() {
this.disabled = true;
recorder.stopRecording(stopRecordingCallback);
};
</script>
<footer style="margin-top: 20px;"><small id="send-message"></small></footer>
<script src="https://cdn.webrtc-experiment.com/common.js"></script>