Video not playing in safari despite range request support

Viewed 1030

I have a streaming server that supports 206 range requests and successfully plays and seeks video on firefox, edge, and chrome. However, when I try to play the same video on Safari--it doesn't work and the video doesn't seem to even load. Any help would be appreciated...

(I'm using react--thus the jsx syntax)

Serverside Code:

try {
    const { range, videoID } = req.requestData;
    const videoPath = "media/" + videoID + ".mp4";
    let videoSize;
    try {
      videoSize = fs.statSync(videoPath).size;
    } catch (err) {
      console.log("Error during video size scan...");
      res.status(500).end();
    }
    // Example: "bytes=32324-"
    const CHUNK_SIZE = 10 ** 6; // 1MB
    const start = Number(range.replace(/\D/g, ""));
    const end = Math.min(start + CHUNK_SIZE, videoSize - 1); // gets the end of the range, start + 1mb or end of video
    const contentLength = end - start + 1;
    
    const headers = {
      "Content-Range": `bytes ${start}-${end}/${videoSize}`,
      "Accept-Ranges": "bytes",
      "Content-Length": contentLength,
      "Content-Type": "video/mp4",
    };
    // HTTP Status 206 for Partial Content
    res.writeHead(206, headers);
    try {
      // create video read stream for this particular chunk
      const videoStream = fs.createReadStream(videoPath, { start, end });

      // Stream the video chunk to the client
      videoStream.pipe(res);
    } catch (err) {
      res.status(500).end();
    }
  } catch (err) {
    res.status(500).end();
    return;
  }

Client-Side code:

        <video controls autoPlay preload="auto" className="w-full h-full">
          <source src={url} type="video/mp4" />
        </video>
1 Answers
Related