angular - 在 angular2 上设置 video.js

标签 angular video.js

我正在使用 video.js 处理我的 angular2 视频,但无法使其正常工作。 我在我的索引文件中使用 video.js CDN。

<link href="https://vjs.zencdn.net/5.11/video-js.min.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/5.11/video.min.js"></script>

我有一个模板文件

<video *ngIf="videoUrl" id="{{id}}"
  class="video-js vjs-big-play-centered"
  controls
  preload="auto"
>
  <source src="{{listing.url}}" type="video/mp4">
</video>

ngAfterViewInit 中包含 video.js 代码的组件

export class ListingComponent implements AfterViewInit, OnInit, OnDestroy {

id: string;

  ngAfterViewInit() {
    videojs(document.getElementById(this.id), {}, function() {
      // Player (this) is initialized and ready.

    });
  }

}

问题是,它显示错误:“找不到名称‘videojs’。”在 ngAfterViewInit

里面

我还尝试通过 npm 安装 video.js 和 import {videojs} from 'video.js 但这也没有用。

有人请帮助我如何使 video.js 与 angular2 一起工作。提前致谢

最佳答案

首先,您没有初始化 videojs。所以它显示 videojs 未定义。

只需在下面找到这段代码:

declare var videojs: any;

export class ListingComponent implements AfterViewInit, OnInit, OnDestroy {

  id: string;
  private videoJSplayer: any;

  constructor() {}

  ngAfterViewInit() {
    this.videoJSplayer = videojs(document.getElementById('video_player_id'), {}, function() {
      this.play();
    });
  }

  ngOnDestroy() {
    this.videoJSplayer.dispose();
  }
}

html:

 <video 
   *ngIf="videoUrl" 
   id="video_player_id"
   class="video-js vjs-big-play-centered"
   controls 
   preload="auto">
   <source src="{{listing.url}}" type="video/mp4">
 </video> 

检查此链接:videojs plunker plunker with answered

关于angular - 在 angular2 上设置 video.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44463487/

相关文章:

Angular 2 RC2 新形式

css - 如何删除 Video.js 中的大播放按钮阴影?

javascript - 如何为 hls.js 创建自定义加载器?

angular - Angular 中支持对象不同错误

Angular2 + PrimeNG - 如何在底层数据更改时重置 dataTable?

Angular 5 Material 5 MatTableDataSource.. ."' mat-card-title' 不是已知元素。”

javascript - 带有 typescript 的Videojs插件

javascript - 在流体模式下限制videojs的高度

html5-video - video.js 在视频末尾显示海报图片

html - 加载另一个组件而不是 root-app-component