视频流返回前端无法播放 #4767
liyang9331
started this conversation in
General
视频流返回前端无法播放
#4767
Replies: 1 comment
-
only => |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
ctx.set('content-type', 'video/mp4');//设置返回类型
let stream = fs.createReadStream('./assets/test.mp4');
if (stream) {//判断状态
stream.on('open', function () {
console.log('文件打开')
});
stream.on('end', function () {
console.log("读取完毕")
})
stream.on('data', function (data) {
// console.log("读取文件流")
ctx.body = data
})
stream.on('err', function () {
console.log("发生错误")
})
stream.on('close', function () {
console.log('关闭')
// ctx.end
});
}
Beta Was this translation helpful? Give feedback.
All reactions