eggjs / eggjs/egg

视频流返回前端无法播放

Open
#4,768 5 comments 0 reactions 0 assignees View on GitHub
Inactive
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

### Discussed in https://github.com/eggjs/egg/discussions/4767

Originally posted by **liyang9331** September 27, 2021
```js
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
});
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.