Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to Stream Data #164

Closed
surajheadsup opened this issue Aug 22, 2022 · 2 comments
Closed

Not able to Stream Data #164

surajheadsup opened this issue Aug 22, 2022 · 2 comments
Labels
stale Closed due to inactivity or lack or resources

Comments

@surajheadsup
Copy link

Hello, I am trying to load the stream into the player but, am not able to load it.

Full Stream Code on Server :

`const express = require("express");
var cors = require("cors");
var ip = require("ip")
const app = express();
const fs = require("fs");
app.use(cors())
app.use('/video/:name', express.static('uploads'))
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});

app.get("/video/:name", function (req, res) {

const range = req.headers.range === undefined ? "byte=0" : req.headers.range;

console.log('inside stream range: ' + JSON.stringify(req.headers));


console.log('range: ' + range);

if (!range) {
    res.status(400).send("Requires Range header");
}
const videoPath = "./video.mp4";
const videoSize = fs.statSync("./video.mp4").size;
const CHUNK_SIZE = 10 ** 6;
const start = Number(range.replace(/\D/g, ""));
const end = Math.min(start + CHUNK_SIZE, videoSize - 1);
const contentLength = end - start + 1;
const headers = {
    "Content-Range": `bytes ${start}-${end}/${videoSize}`,
    "Accept-Ranges": "bytes",
    "Content-Length": contentLength,
    "Content-Type": "video/mp4",
}; 

res.writeHead(206, headers);
const videoStream = fs.createReadStream(videoPath, { start, end });
videoStream.pipe(res);

});

app.get("/final", function (req, res) {

var path = __dirname;

console.log('path', path);
res.sendFile(path+'/video.mp4')

});

app.listen(3004, function () {
console.log("Listening on port 3004!");
console.log('ip address', ip.address());
});`

I have tried both first stream data and other server file as static, Static file working fine but stream not loading

Copy link
Contributor

github-actions bot commented Dec 4, 2024

This issue is stale because it has been open for 30 days with no activity. If there won't be any activity in the next 14 days, this issue will be closed automatically.

@github-actions github-actions bot added the stale Closed due to inactivity or lack or resources label Dec 4, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Closed due to inactivity or lack or resources
Projects
None yet
Development

No branches or pull requests

2 participants
@surajheadsup and others