How to fix err_request_range_not_satisfiable error which occurs when I try to view a video recorded on the browser?
Asked Answered
T

1

11

I am new to react and I am trying to develop a web application with video recording capabilities. This is my code: App.js:

import ScreenRecording from './Recorder'

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <ScreenRecording />
      </header>
    </div>
  );
}

export default App;

Recorder.js:

import './Recorder.css'
import React from 'react';
import ReactDom from 'react-dom';
import axios from "axios";

const ScreenRecording = () => {
  
  var strName = null;
  var strEmail = null;
  const video = document.getElementById('video');

  async function captureMediaDevices(mediaConstraints = {
      video: {
        width: 1280,
        height: 720
      },
      audio: {
        echoCancellation: true,
        noiseSuppression: true,
        sampleRate: 44100
      }
    }) {
    const stream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
    
    video.src = null;
    video.srcObject = stream;
    video.muted = true;
    
    return stream;
  }
  
  let recorder = null;
  var strFile = null;
  var webcamblob = null;

  function stopRecording() {
   recorder.stream.getTracks().forEach(track => track.stop());
  }

  async function recordVideo() {
    
    const stream = await captureMediaDevices();
    
    video.src = null;
    video.srcObject = stream;
    video.muted = true;
    video.autoplay = true;
    
    recorder = new MediaRecorder(stream);
    let chunks = [];
  
    recorder.ondataavailable = event => {
      if (event.data.size > 0) {
        chunks.push(event.data);
      }
    }
    
    recorder.onstop = () => {
      const blob = new Blob(chunks, {
        type: 'video/webm'
      })
      chunks = [];
      webcamblob = blob;
      const blobUrl = URL.createObjectURL(blob);
      strFile = blobUrl;

     }

    recorder.start(200);
  }

  const previewRecording = () => {
    video.srcObject = null;
    video.src = strFile;
    video.muted = false;
    video.autoplay = true;
  }

  const uploadRecording = () => {

    strName = document.getElementById("name").value;
    strEmail = document.getElementById("email").value;

    const formData = new FormData();

    // Update the formData object
    formData.append("file2upload", webcamblob);
    formData.append("email", strEmail);
    formData.append("name", strName);

    // Request made to the backend api
    // Send formData object
    axios.post("https://xyz.php", formData);

    cleardata();
    
    alert("Upload success!");
  };

  const cleardata = () => {
      URL.revokeObjectURL(strFile);
      webcamblob = null;
  }

  return(
      <center>
      <div>
        <button onClick={recordVideo}>Record video</button>
        <button onClick={stopRecording}>Stop recording</button>
        <button onClick={previewRecording}>Replay</button>
        <button onClick={uploadRecording}>Upload and close</button>
      </div>
      </center>
  )
}
function Video(){
  return (<div className="Display">
            <center>
              <video id='video' className="Display-video" width="800" height="600" autoplay muted></video>
            </center>
          </div>)
}

ReactDom.render(
  <React.StrictMode>
  <Video />
  </React.StrictMode>,
  document.getElementById('vid')
);

export default ScreenRecording;

The program was working as expected until recently. Presently, It is not working and when I try to replay the recorded video using the "Replay" button, the browser console is returning the error: net::ERR_REQUEST_RANGE_NOT_SATISFIABLE. When the blob size is read, it is zero. Can someone please help to fix the issue?

Totter answered 27/1, 2022 at 9:27 Comment(4)
did you get answer?Elderberry
No, I have not got an answer yet. But surprisingly the code is working now. I think it is some browser issue.Totter
I also fixed this I was trying to merge multiple blogs but get this issue multiple times. Now I figured out the problem after using MultiStreamMixer and now I can record two media streams ( or merging two streams into one).Elderberry
@AmitDagar Hi, how did you do it ?Counselor
W
2

I had the same issue. Turned out that my blob was 0 size after using a fetch op with no-cors, and hence the video complaining about range.

Wellturned answered 6/5 at 16:30 Comment(1)
Same issue here, after successfully uploading to s3, the initial hits gets not found, I had to use a retryMohandas

© 2022 - 2024 — McMap. All rights reserved.