Last active
August 29, 2015 13:59
-
-
Save sonianand11/10638767 to your computer and use it in GitHub Desktop.
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
<script> | |
$(document).ready(function(){ | |
var startRecording = document.getElementById('start-recording'); | |
var stopRecording = document.getElementById('stop-recording'); | |
var uploadRecordingBtn = document.getElementById('upload-recording'); | |
var cameraPreview = document.getElementById('camera-preview'); | |
var timeoutInt = 0; | |
var secondCount; | |
var audio = document.querySelector('audio'); | |
navigator.getUserMedia = navigator.getUserMedia || | |
navigator.webkitGetUserMedia || navigator.mozGetUserMedia || | |
navigator.msGetUserMedia; | |
var recordAudio, recordVideo; | |
startRecording.onclick = function() { | |
navigator.getUserMedia = navigator.getUserMedia || | |
navigator.webkitGetUserMedia || navigator.mozGetUserMedia || | |
navigator.msGetUserMedia; | |
navigator.getUserMedia({ | |
audio: true | |
}, function(stream) { | |
recordAudio = RecordRTC(stream, { | |
bufferSize: 16384 | |
}); | |
navigator.getUserMedia({ | |
video: true | |
}, function(stream2) { | |
cameraPreview.src = window.URL.createObjectURL(stream2); | |
cameraPreview.play(); | |
recordVideo = RecordRTC(stream2); | |
stopRecording.disabled = false; | |
uploadRecordingBtn.disabled = true; | |
startRecording.disabled = true; | |
recordAudio.startRecording(); | |
recordVideo.startRecording(); | |
}, function(error) { | |
alert(JSON.stringify(error)); | |
}); | |
stopRecording.disabled = false; | |
uploadRecordingBtn.disabled = true; | |
startRecording.disabled = true; | |
}, function(error) { | |
alert(JSON.stringify(error)); | |
}); | |
secondCount = 1; | |
setTimer(secondCount); | |
}; | |
stopRecording.onclick = function() { | |
stopRecordingAll(); | |
}; | |
uploadRecordingBtn.onclick = function() { | |
startRecording.disabled = false; | |
stopRecording.disabled = true; | |
//uploadRecordingBtn.disabled = true; | |
uploadBlob(); | |
}; | |
function stopRecordingAll(){ | |
cameraPreview.src = null; | |
startRecording.disabled = false; | |
stopRecording.disabled = true; | |
uploadRecordingBtn.disabled = false; | |
recordAudio.stopRecording(); | |
recordVideo.stopRecording(); | |
clearTimeout(timeoutInt); | |
} | |
function setTimer(secondCount){ | |
if(secondCount < 12){ | |
document.getElementById("txt").innerHTML="seconds : "+secondCount ; | |
secondCount++; | |
timeoutInt = setTimeout( | |
function(){ | |
setTimer(secondCount); | |
}, | |
1000); | |
}else{ | |
clearTimeout(timeoutInt); | |
alert("You reach to maximum limit of 11 seconds"); | |
stopRecordingAll(); | |
} | |
} | |
function uploadBlob(){ | |
var fd = new FormData(); | |
var vblob = new Blob([recordVideo.getBlob()],{type: "video/webm"}) | |
var ablob = new Blob([recordAudio.getBlob()],{type: "audio/ogg", endings: 'native' }) | |
fd.append('videoBlob', vblob); | |
fd.append('audioBlob',ablob); | |
fd.append('firefox',true); | |
$.ajax({ | |
type: 'POST', | |
url: '/uploadBlob', | |
data: fd, | |
processData: false, | |
contentType: false | |
}).done(function(data) { | |
console.log(data); | |
resultVideo = document.getElementById("result_camera") | |
resultVideo.src = document.location.origin+data.video_url | |
resultVideo.play(); | |
}); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment