【问题标题】:How to use Video.js with Ionic 2 + Angular 2如何在 Ionic 2 + Angular 2 中使用 Video.js
【发布时间】:2018-04-10 22:16:08
【问题描述】:

Q) 谁能给我一个简单的工作示例,说明如何在 Ionic 2 的组件/页面中包含 video.js,最好是居中的大播放按钮?

背景:

我一直在尝试让 video.js 与我的 Ionic 2 应用程序一起使用以呈现视频列表,但我就是想不通。

当我有标记时,我的视频会呈现:

<ion-row *ngFor="let item of videoList">
    <video id="my-player-{{item.id}}" class="video-js vjs-default-skin" 
        controls preload="auto" data-setup='{}'>
        <source src="{{item.previewVideoUrl}}" type="video/mp4">
    </video>
</ion-row>  

铬:

..但这显然只是浏览器内置的 html5 播放器,而不是 video.js 播放器,因为它在 chrome + safari 中呈现的效果并不像人们期望的那样:

Safari:

【问题讨论】:

    标签: angular ionic2 html5-video video.js


    【解决方案1】:

    从 npm 安装模块,即

    npm install video.js --save
    npm install -s safe-json-parse
    

    然后就可以在组件中初始化播放器了:

    在 html 中:

    <video id="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered vjs-16-9" controls preload="auto">
        <source [src]="url" type="video/mp4" />
    </video>
    

    然后在你的代码中:

    import videojs from 'video.js';
    
    public url: string = "https://someurltovideo.com/wowsers/mp4"
    ...
    
    
    initPlayer() {
        try {
            // setup the player via the unique element ID
            var element = document.getElementById('videoPlayer');
            if (element == null) {
                throw "error loading blah";
            }
            // if we get here, all good!
            videojs(element, {}, () => { });
        }
        catch (e) {
        }
    }
    

    【讨论】:

    • 嘿@Dave,你能更新一下plunkr的链接吗?显示无法加载
    猜你喜欢
    • 1970-01-01
    • 2016-06-26
    • 2016-04-18
    • 1970-01-01
    • 2017-04-08
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多