Czasami pojawia się błąd na moim serwerze Node.js, który mówi mi, że req.headers.range
jest niezdefiniowany, gdy użytkownik żąda .mp4
(nie próbowałem podawać żadnych innych typów plików wideo, nie jestem pewien, czy MP4 jest istotny). Nie rozumiem, dlaczego brakuje tego nagłówka.Nagłówek zakresu brakuje na żądanie wideo?
Czy nagłówek żądania filmu wideo może czasami nie zawierać numeru range
?
wyślę strumień tak:
var videoReqHandler = function(req, res, pathname) {
var file = dirPath + "/Client" + pathname;
var range = req.headers.range;
var positions = range.replace(/bytes=/, "").split("-");
var start = parseInt(positions[0], 10);
fs.stat(file, function(err, stats) {
if (err) {
throw err;
} else {
var total = stats.size;
var end = positions[1] ? parseInt(positions[1], 10) : total - 1;
var chunksize = (end - start) + 1;
res.writeHead(206, {
"Content-Range" : "bytes " + start + "-" + end + "/" + total,
"Accept-Ranges" : "bytes",
"Content-Length" : chunksize,
"Content-Type" : "video/mp4"
});
var stream = fs.createReadStream(file, {
start : start,
end : end
}).on("open", function() {
stream.pipe(res);
}).on("error", function(err) {
res.end(err);
});
}
});
};
Błąd:
/video_stream.js:21
var positions = range.replace(/bytes=/, "").split("-");
TypeError: Cannot call method 'replace' of undefined