首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在video.js上安装angular2

在video.js上安装angular2
EN

Stack Overflow用户
提问于 2017-06-09 17:18:46
回答 4查看 6.5K关注 0票数 3

我正在使用video.js在我的angular2 vidoes上工作,但无法使它工作。我在索引文件中使用video.js CDN。

代码语言:javascript
复制
<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>

我有一个模板文件

代码语言:javascript
复制
<video *ngIf="videoUrl" id="{{id}}"
  class="video-js vjs-big-play-centered"
  controls
  preload="auto"
>
  <source src="{{listing.url}}" type="video/mp4">
</video>

以及在video.js中使用ngAfterViewInit代码的组件。

代码语言:javascript
复制
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和import {videojs} from 'video.js安装video.js,但这也不起作用。

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-06-10 07:45:26

首先,您没有初始化视频the。所以它显示的视频So没有定义。

只需在下面的代码中找到:

代码语言:javascript
复制
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:

代码语言:javascript
复制
 <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> 

检查此链接:视频柱塞 有答案的柱塞

票数 5
EN

Stack Overflow用户

发布于 2018-01-19 15:21:35

由于2+通过向组件下的每个元素添加_ng-content-c*属性并向样式添加相同的属性来使用ViewEncapsulation,因此需要禁用此特性来集成第三方库(如VideoJS )。

您的组件定义应该如下所示:

代码语言:javascript
复制
@Component({
  selector: 'app-player',
  templateUrl: 'component.html',
  styleUrls: [
    'component.scss',
    '../../../node_modules/video.js/src/css/video-js.scss',
  ],
  encapsulation: ViewEncapsulation.None, // This plus the sytleUrl are the important parts
})
export class PlayerComponent implements OnInit, AfterViewInit {
}
票数 3
EN

Stack Overflow用户

发布于 2018-02-15 21:23:54

在使用角4+和角CLI时,我发现最好的解决方案是通过npm包安装,然后将视频in添加到angular-cli.json中的脚本中,如下所示:

代码语言:javascript
复制
"scripts": [
    "../node_modules/video.js/dist/video.min.js"
]

然后,将其添加到您的typings.d.ts中。

代码语言:javascript
复制
declare const videojs: any;

然后按照正常的方式输入:

代码语言:javascript
复制
ngAfterViewInit() {
  this._videoPlayer = videojs(document.getElementById('video'), {}, () => {});
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44463487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档