I'm doing a questionnaire system for a client. From this questionnaire some questions should be answered by video. When opening the page of the question the camera already begins to record the user. I am able to write the video, save to a JavaScript object and run it in the browser. However I'm having trouble playing this file / object in an input type="file" to get it to the server.
I have a tight deadline ... if anyone can give me a light I would greatly appreciate it.
var video = document.querySelector('video');
function captureCamera(callback) {
navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then(function(camera) {
callback(camera);
}).catch(function(error) {
alert('Erro ao acessar a camera/microfone.');
console.error(error);
});
}
function stopRecordingCallback() {
video.src = video.srcObject = null;
video.src = URL.createObjectURL(recorder.getBlob());
//video.play();
recorder.camera.stop();
//recorder.destroy();
//recorder = null;
sendForm();
}
var recorder; // globally accessible
function startRecord() {
this.disabled = false;
captureCamera(function(camera) {
setSrcObject(camera, video);
video.play();
recorder = RecordRTC(camera, {
type: 'video'
});
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);
};
startRecord();
function sendForm(){
document.getElementById('tempoInput').value = tempo;
document.questiontime.submit();
}
<html>
<body>
<video width="380" height="280" style="background: #eee;"></video>
<form name="questiontime" action="../controllers/sectionInterview.php" method="post">
<input type="file" id="InputVideo" name="videofile" value="" style="display: none;">
</form>
<button type="button" id="btn-stop-recording">Continuar</button>
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"></script><scriptsrc="https://webrtc.github.io/adapter/adapter-latest.js"></script>
</body>
</html>
In the sendForm () function I tried to create a way to set the object in the input before submitting the form, but without success ...
Thanks for the help!