cloudflarestream - 将 Cloudflare 播放器集成到 Cloudflare 流的 Angular 7 中
问题描述
我正在尝试让 cloudflare 流以角度工作。我已经尝试过这里给出的解决方案:Angular attribute for HTML stream。
然而,它总是一个成功或失败:
- 在 10 次重新加载中,有一次加载播放器。
- 但是每当我对
<stream>
标签进行更改并重新编译角度时,都会加载播放器。在此之后,如果我刷新浏览器,它又是一个空白屏幕。
显示视频的组件在树的深处,并且该组件属于延迟加载的模块:
在 index.html 文件中:
<!doctype html>
<html lang="en">
<head>
...............
</head>
<body>
<app-root></app-root>
</body>
<script src="https://embed.cloudflarestream.com/embed/r4xu.fla9.latest.js" id="video_embed" defer="" async=""></script>
</html>
在 videoFile.component.ts 中:
<stream src="5d5bc37ffcf54c9b82e996823bffbb81" height="480px" width="240px" controls></stream>
解决方案
在这里找到了解决方案:https ://github.com/angular/angular/issues/13965
因此,每次加载组件时,都会使用 ngOninit 删除并重新附加脚本,如下所示:
document.getElementById("video_embed").remove();
let testScript = document.createElement("script");
testScript.setAttribute("id", "video_embed");
testScript.setAttribute("src", "https://embed.cloudflarestream.com/embed/r4xu.fla9.latest.js");
document.body.appendChild(testScript);
如果有人有其他解决方案,请告诉我。
推荐阅读
- omnet++ - 如何在 Veins 4.7.1 中配置双 802.11p 无线电
- javascript - 消息通知
- java - 我可以通过在子类中包含父类以递归方式反序列化 json 吗?
- c - 打印pid和errno
- swift - 可选类型“浮点数?”的值 必须解包为“Float”类型的值
- ios - 未调用 DidRefreshRegistrationToken,即使在卸载/安装之后也是如此。如何在 xamarin IOS 中获取已生成的 firebase 令牌,
- c# - youtube使用c#中的rest api上传问题?
- asp.net - 将剃须刀页面转换为 Angular 6 视图
- php - 从另一个表中插入具有一个值的数据 Mysql
- android - gradle实现依赖的继承类不能在另一个模块中使用