问题描述
我看了在similar question中回答的解决方案。但是,它并不能解决我的问题。
从Nodejs服务器提供服务时,在AWS S3
浏览器上的Safari
上托管的视频加载过程中出现问题。 Chrome
浏览器没有任何问题。
http:// localhost:3000 / stream(由我的NodeJS
服务器提供)在Chrome
上加载正常,但在Safari
上加载正常。
这是我的HTML
代码:
<!DOCTYPE HTML>
<html>
<head>
<title>test</title>
</head>
<body>
<video id="vid1" controls preload="auto" src="http://localhost:3000/stream"></video>
</body>
</html>
这是我的NodeJS
代码:
app.get('/stream',function(req,res) {
var s3 = new AWS.S3();
const mimetype = 'video/mp4';
const file = 'awss3 file name (ex:bunny.mp4 )';
const cache = 0;
console.log('const mimetype,file,and cache declared');
var bucketPath = "sample Bucket Name ;
s3.listObjectsV2({ Bucket: bucketPath,MaxKeys: 1,Prefix: file },function(err,data) {
if (err) {
return res.sendStatus(404);
}
console.log('made request to s3 to list objects');
if ((req != null) && (req.headers.range != null)) {
var range = req.headers.range;
var bytes = range.replace(/bytes=/,'').split('-');
var start = parseInt(bytes[0],10);
var total = 32508526;
// size of the video
var end = bytes[1] ? parseInt(bytes[1],10) : total - 1;
var chunksize = (end - start) + 1;
console.log('declared range,bytes,start,total,end,chunksize vars');
res.writeHead(206,{
'Content-Range': 'bytes ' + start + '-' + end + '/' + total,'Accept-Ranges': 'bytes','Content-Length': chunksize,// 'Content-Length': 32508526,// 'Last-Modified': data.Contents[0].LastModified,// 'Content-Type': mimetype
'Content-Type': 'video/mp4',});
console.log('wrote header');
s3.getObject({ Bucket: bucketPath,Key: file,Range: range }).createReadStream(data,{ start,end }).pipe(res);
console.log('got object from s3 and created readstream');
} else {
console.log(data);
var total = 32508526;
res.writeHead(200,{
'Content-Length': total,'Content-Type': 'video/mp4',});
s3.getObject({ Bucket: bucketPath,Key: file }).createReadStream().pipe(res);
console.log('fell into else statement,wrote header');
}
});
});
这里可能是什么问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)