angular - videojs 无法在 Angular 2 应用程序中工作

标签 angular video.js

我使用的组件具有通过订阅执行视频 URL 的功能。

只有当url存在时才会显示该标签。

video标签被正常触发,但是css没有被执行。 我正在使用 video-js 来进行视频标记。

this.postServices.getPost(id).subscribe( (res) => {

this.video = 'http://127.0.0.1:9111/api/get/video.mp4';

})

模板

<video *ngIf="video"
                 class="video-js"
                 controls preload="metadata" autoplay="true" >
              <source [src]="video" type="video/mp4" />
          </video>

最佳答案

记得添加:

<link href="http://vjs.zencdn.net/6.2.8/video-js.css" rel="stylesheet">

致您的<head></head> index.html 中的部分

还将 videojs 脚本添加到您的 index.html 中:

<script src="http://vjs.zencdn.net/6.2.8/video.js"></script>

然后,当您在服务中运行对 url 的请求时,您应该初始化播放器:

declare let videojs: any; // just to avoid TS stuffs for this demo
player: any;

this.postServices.getPost(id).subscribe( (res) => {
    this.video = 'http://127.0.0.1:9111/api/get/video.mp4';
    // Just to be sure that you have the video tag available
    setTimeout(() => player = videojs('player'), 100);
})

模板:

      <video *ngIf="video" id="player"
             class="video-js"
             controls preload="metadata" autoplay="true" >
          <source [src]="video" type="video/mp4" />
      </video>

这样应该可以工作,但这不是 *ngIf 的问题,这与 videojs 的使用有关库。

关于angular - videojs 无法在 Angular 2 应用程序中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47023487/

相关文章:

jquery - 如何使用 video.js 播放()从 JQuery 注入(inject) load() 的 <video> ?

angular - 基于当前 URL 的条件 ngClass

css - 无法为 ng-sidebar 设置背景

video.js - 带有 video.js flash 后备的 HTTP 动态流

javascript - VideoJS v5 - 在 ES6 中添加自定义组件 - 我做得对吗?

video.js - 如何使用videojs播放rtmp直播?

javascript - Video.js 5 中的 showTextTrack

css - 如何在 Angular2 中为 WebComponents 添加样式

javascript - 是否可以使用 TypeScript 将 HTML 文件作为字符串导入?

c# - 如何修复 HttpErrorResponse 404 未找到