Javascript 尝试从Node.js以Angular格式流式传输视频
我正在从Node.js/Express.js向我的Angular前端应用程序发送视频。数据正在分块发送,我想在Angular应用程序中播放视频。不幸的是,有些东西似乎不起作用。 谁能告诉我我做错了什么 Courses.Component.html Node.js 视频根本没有播放。我在网上搜索了很多,但找不到任何帮助。 如果有人能帮忙,我将不胜感激。 谢谢编辑此文件以便任何人都能提供帮助Javascript 尝试从Node.js以Angular格式流式传输视频,javascript,node.js,angular,typescript,express,Javascript,Node.js,Angular,Typescript,Express,我正在从Node.js/Express.js向我的Angular前端应用程序发送视频。数据正在分块发送,我想在Angular应用程序中播放视频。不幸的是,有些东西似乎不起作用。 谁能告诉我我做错了什么 Courses.Component.html Node.js 视频根本没有播放。我在网上搜索了很多,但找不到任何帮助。 如果有人能帮忙,我将不胜感激。 谢谢编辑此文件以便任何人都能提供帮助 <div class="video-player-wrapper">
<div class="video-player-wrapper">
<video id = "videoPlayer" controls preload = "metadata" style = "width: 65%; position: fixed;
border: 2px solid #7c2c6c;">
<source [attr.src]="courseVideo" autoplay type = "video/mp4">
</video>
</div>
const params = new HttpParams().set('id', this.findcourseservice.getUserSelected()).set('id2',
this.courseContent).set('id3', courseToPlay);
this.http.get('http://localhost:3000/playVideo', {params, responseType: "blob"})
.subscribe(response => {
const reader = new FileReader();
this.courseVideo = reader.readAsArrayBuffer(response);
})
router.get('/playVideo', (req, res) => {
const viewCourse = req.query.id;
const viewSubCourse = req.query.id2;
const videoLink = req.query.id3;
const path = `D:/Videos/${viewCourse}/${viewSubCourse}/${videoLink}`;
const stat = fs.statSync(path);
const fileSize = stat.size;
const head = {
'Content-Length': fileSize,
'Accept-Ranges' : 'bytes',
'Content-Type': 'video/mp4'
}
res.writeHead(200, head);
fs.createReadStream(path).pipe(res);
});