videojs-panorama
videojs-panorama copied to clipboard
Status 416 Requested Range Not Satisfiable
Hi, i am using plugin on website, sometimes video file takes too long to load so i got Status 416 Requested Range Not Satisfiable on .mp4 files.
When there is no 416 status video file loads and plays perfectly, at that time there is status 206. This happens about 50% of time, depends on internet speed.
Would increasing Accept-Ranges:bytes helps ? Any solutions ?
Hey, did you use nodejs server?
I have the same problem before. MP4 video on real server needs to do buffering. So it's possible to play the video in middle without download the full video. If this didn't be set on server level, it will have problem.
check the following code if you use nodejs
if(type == "video/mp4" || type == "audio/mp4" || type == "video/webm" || type == "audio/webm" || type == "video/ogg" || type == "audio/ogg" || type == "video/mpeg"
|| type == "video/h264" || type == "video/x-flv" || type == "video/3gpp" || type == "video/3gpp2"){
var stat = fs.statSync(filePath);
var total = stat.size;
if (req.headers['range']) {
var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1;
var chunksize = (end-start)+1;
var file = fs.createReadStream(filePath, {start: start, end: end});
res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': type });
file.pipe(res);
} else {
res.writeHead(200, { 'Content-Length': total, 'Content-Type': type });
fs.createReadStream(filePath).pipe(res);
}
return;
}