Thanks for all of your previous help.
I am testing this new code, where video is captured/recorded successfully. However, I don’t have the upload part correct. Nothing happens upon selecting the upload button:
and the js:
any assistance is appreciated
I am testing this new code, where video is captured/recorded successfully. However, I don’t have the upload part correct. Nothing happens upon selecting the upload button:
HTML:
<button id="button1" onclick="startRecording()">Start</button>
<button id="button2" onclick="endRecording()">Stop</button>
<button id="fileupload">Upload File</button>
<video id="video" autoplay="autoplay" controls="controls" poster="/thumbnail.jpg" type="video/mp4" muted playsInline><source src="source.mp4" type="video/mp4"></video>
and the js:
JavaScript:
function supportsRecording(mimeType)
{
if (!window.MediaRecorder)
return false;
if (!MediaRecorder.isTypeSupported)
return mimeType.startsWith("audio/mp4") || mimeType.startsWith("video/mp4");
return MediaRecorder.isTypeSupported(mimeType);
}
var video = document.querySelector('#video');
let blobs = [];
let stream;
let mediaRecorder;
async function startRecording()
{
stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (event) => {
// Let's append blobs for now, we could also upload them to the network.
if (event.data)
blobs.push(event.data);
}
mediaRecorder.onstop = doPreview;
// Let's receive 1 second blobs
mediaRecorder.start(1000);
}
function endRecording()
{
// Let's stop capture and recording
mediaRecorder.stop();
stream.getTracks().forEach(track => track.stop());
}
function doPreview()
{
if (!blobs.length)
return;
// Let's concatenate blobs to preview the recorded content
video.src = URL.createObjectURL(new Blob(blobs, { type: mediaRecorder.mimeType }));
}
//////////////////////////////////////////////////////////////////////////////////////////////////
async function uploadFile() {
let formData = new FormData();
formData.append("file", fileupload.files[0]);
await fetch('/upload.php', {
method: "POST",
body: formData
});
alert('The file has been uploaded successfully.');
}
any assistance is appreciated