From 9f5fbac6d9ad8cf4c6eed49d80730092763bf73a Mon Sep 17 00:00:00 2001 From: Andrew Braae Date: Sun, 30 Jun 2024 01:34:21 +1200 Subject: [PATCH] Update hello.html --- hello.html | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hello.html b/hello.html index ca1c7c2..eafff57 100644 --- a/hello.html +++ b/hello.html @@ -1,7 +1,7 @@ - RecordRTC with timeSlice + RecordRTC with Selective Slices Combination @@ -39,20 +39,26 @@ stopRecordingButton.onclick = () => { recorder.stopRecording(() => { - // Combine only the last four recorded blobs - let lastFourBlobs = recordedBlobs.slice(-4); - let combinedBlobs = new Blob(lastFourBlobs, { type: 'video/webm' }); + // Select the first slice and the last four slices + let selectedBlobs = []; + if (recordedBlobs.length > 0) { + selectedBlobs.push(recordedBlobs[0]); + } + if (recordedBlobs.length > 4) { + selectedBlobs.push(...recordedBlobs.slice(-4)); + } else { + selectedBlobs.push(...recordedBlobs); + } - // Create URL for combined Blob - let url = URL.createObjectURL(combinedBlobs); - video.srcObject = null; - video.src = url; - video.controls = true; + // Combine selected blobs into one + let superBuffer = new Blob(selectedBlobs, { type: 'video/webm' }); + let url = URL.createObjectURL(superBuffer); - // Create downloadable link downloadLink.href = url; downloadLink.download = 'recorded-video.webm'; downloadLink.style.display = 'block'; + video.srcObject = null; + video.src = url; stream.getTracks().forEach(track => track.stop()); startRecordingButton.disabled = false;