Ionic3学习笔记(十四)使用 videogular2 实现视频播放以及遇到的一些问题

本文为原创文章,转载请标明出处

目录

  1. 使用 videogular2
    • 安装
    • 增加图标、字体支持
    • 导入 module
    • 举个例子
  2. 遇到的问题
    • iOS 端自动进入全屏播放
    • Android 端 autoplay 不起作用
  3. 更多

1. 使用 videogular2

安装

终端运行:

npm install videogular2 --save
npm install @types/core-js --save-dev

增加图标、字体支持

videogular2 GitHub 地址:https://github.com/videogular/videogular2

git clone 下来,将它的 fonts 文件夹 copy 到你的 Ionic 项目的 assets 文件夹中,在 index.html 中引入 videogular 的 css 文件:

<link rel="stylesheet" href="assets/fonts/videogular.css">

导入 module

导入你要使用 videogular2 的 page 的 module,比如说我要在 trailer.html 中使用,那我就导入到 trailer.module.ts 中。

import {NgModule} from '@angular/core';
import {IonicPageModule} from 'ionic-angular';
import {VgCoreModule} from 'videogular2/core';
import {VgControlsModule} from 'videogular2/controls';
import {VgOverlayPlayModule} from 'videogular2/overlay-play';
import {VgBufferingModule} from 'videogular2/buffering';
import {TrailerPage} from './trailer';

@NgModule({
  declarations: [
    TrailerPage,
  ],
  imports: [
    VgCoreModule,
    VgControlsModule,
    VgOverlayPlayModule,
    VgBufferingModule,
    IonicPageModule.forChild(TrailerPage),
  ],
})
export class TrailerPageModule {
}

举个例子

  <vg-player>
    <vg-overlay-play></vg-overlay-play>
    <vg-buffering></vg-buffering>
    <vg-controls [vgAutohide]="true" [vgAutohideTime]="5">
      <vg-play-pause></vg-play-pause>
      <vg-time-display [vgProperty]="'current'"></vg-time-display>
      <vg-scrub-bar>
        <vg-scrub-bar-current-time [vgSlider]="true"></vg-scrub-bar-current-time>
        <vg-scrub-bar-buffering-time></vg-scrub-bar-buffering-time>
      </vg-scrub-bar>
      <vg-time-display [vgProperty]="'total'"></vg-time-display>
      <vg-fullscreen></vg-fullscreen>
    </vg-controls>
    <video #media [vgMedia]="media" poster="你的poster" src="你的src" autoplay></video>
  </vg-player>

2. 遇到的问题

iOS 端自动进入全屏播放

video 标签加上 playsinline(iOS 10及以上)、webkit-playsinline(iOS 10之前)这两个属性。

另外还需要在 config.xml 文件中加上

<preference name="AllowInlineMediaPlayback" value="true" />

Android 端 autoplay 不起作用

这是谁的锅…说来话长…不管了…

3. 更多

  1. GitHub - videogular2
  2. videogular2 docs
  3. Cordova - Congig.xml

如有不当之处,请予指正,谢谢~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值