Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

video recording using html , js

<div id="wap">
  <div class="form-group">
    <label>Record Your Video</label>
    <br>
    <video autoplay="" muted id="stream-elem"  width="100%" height="350px">
    <source src="" type=""  >
    </video>
    <div id="recwap"></div>
    <button onclick="startrecording()" type="button" id="start-stream" class="btn btn-success">Start Recording</button>
    <button onclick="endrecording()" type="button" id="stop-media" class="btn btn-primary">Stop Recording</button>
  </div>
</div>

<script>
var recorder;
var blobContainer = [];
const settings = {
video: true,
audio: true
}
// $('#recorded').hide();
function startrecording(){
    var videoElem = document.getElementById('stream-elem');
    var endBtn = document.getElementById('stop-media');
    $('#stop-media').show();
    $('#stream-elem').show();
    $("#recordv").remove();

    blobContainer = [];
    navigator.mediaDevices.getUserMedia(settings).then((stream) => {
        // console.log(stream);
        videoElem.srcObject = stream

        recorder = new MediaRecorder(stream)
        // console.log(recorder);
        recorder.start();

        recorder.ondataavailable = function (e) {
            
            blobContainer.push(e.data)
        }

        recorder.onerror = function (e) {
            return console.log(e.error || new Error(e.name));
        }
        
        recorder.onstop = function (e) {
            $('#stream-elem').hide();
            var newVideoEl = document.createElement('video')
            newVideoEl.autoplay = true
            newVideoEl.controls = true
            newVideoEl.id = 'recordv'
            newVideoEl.innerHTML = `<source src="${window.URL.createObjectURL(new Blob(blobContainer))}" type="video/mp4">`;
            var recwap = document.getElementById('recwap')
            recwap.appendChild(newVideoEl);	
        }



    })
}   



function endrecording(){
    var videoElem = document.getElementById('stream-elem');
    videoElem.pause();
    recorder.stop();
}
 
</script>
Source by developers.google.com #
 
PREVIOUS NEXT
Tagged: #video #recording #html #js
ADD COMMENT
Topic
Name
4+6 =