问题描述
很抱歉问题标题给您带来的不便,但我不知道如何描述问题。
我有以下代码来处理远程视频并将其通过管道传输到响应(使用 html5 视频标签在浏览器中播放):
const express = require('express')
//url: https://www.example.com/video.mp4
const http = require('https')
const app = express()
app.get('/',(req,res) => {
http.get(url,(httpRes) => {
httpRes.pipe(res)
})
})
我也尝试使用 got
npm 模块:
got.stream(url).pipe(res)
问题是:如果视频持续时间不是那么长(即 3 分钟),这两种方法都可以正常工作,但如果是(即超过 35 分钟),它将无法获取整个视频,而是给了我前 2:54 分钟。
可能是什么问题? 我能做些什么来解决它? 感谢大家的任何帮助。
编辑:
我的完整代码:
const express = require('express')
const url = 'https://www.example.com/video.mp4'
const fs = require('fs')
const http = require('https')
const app = express()
const port = 3000
// the main request is made by the client to this endopoint '/'
app.get('/',res) => {
//the server responds by sending 'player.html' file
res.sendFile(__dirname + '/player.html')
})
// this request is made by the <video> tag in 'player.html'
app.get('/video',(response) => {
response.pipe(res)
})
player.html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<video id="videoPlayer" controls width="100%" height="auto">
<source src='/video' type="video/mp4">
</video>
</body>
</html>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)