无法在由Node.js服务器提供的iPhone Safari浏览器中播放mp4视频

问题描述

我看了在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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...