Created
October 4, 2018 23:42
-
-
Save henryhamon/305c397bd79cb27015ced9a11878574c to your computer and use it in GitHub Desktop.
record cam and screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const recordCamera = () => { | |
smallVideoType=1; | |
cleanRecord() | |
navigator.getUserMedia({ | |
audio: false, | |
video: { mandatory: { minWidth: 50, minHeight: 50 } } | |
}, getMediaStream, getUserMediaError) | |
} | |
const getMediaStream = (stream) => { | |
var video = document.querySelector('video') | |
video.src = URL.createObjectURL(stream) | |
localStream = stream | |
stream.onended = () => { console.log('Media stream ended.') } | |
let videoTracks = localStream.getVideoTracks() | |
if (includeMic) { | |
console.log('Adding audio track.') | |
let audioTracks = microAudioStream.getAudioTracks() | |
localStream.addTrack(audioTracks[0]) | |
} | |
try { | |
console.log('Start recording the stream.') | |
recorder = new MediaRecorder(stream) | |
} catch (e) { | |
console.assert(false, 'Exception while creating MediaRecorder: ' + e) | |
return | |
} | |
recorder.ondataavailable = recorderOnDataAvailable | |
recorder.onstop = () => { console.log('recorderOnStop fired') } | |
recorder.start() | |
console.log('Recorder is started.') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment