components

Components

Video.js播放器的架构围绕组件。 Player类和所有表示播放器控件和其他UI元素的类都继承自Component类。 这种架构使得可以轻松地以反映DOM的树状结构构建Video.js播放器的用户界面。

目录

  • 组件是什么?
  • 创建一个组件
  • 子组件
    • 基本例子
    • 使用选项
  • 时间监听
    • Using on
    • Using off
    • Using one
    • Using trigger
  • 默认组件树
  • 特定组件详细信息
    • 音量面板
    • 文本轨道设置

组件是什么?

组件是具有以下功能的JavaScript对象:

  • 相关联的DOM元素.
  • 与Player对象的结合.
  • 能够管理任意数量的子组件.
  • 监听和触发事件的能力.
  • 初始化和处置的生命周期.

有关组件编程接口的更多详细信息,请参阅组件API文档。

创建组件

Video.js组件可以继承并注册到Video.js以向播放器添加新功能和UI。

对于一个工作示例,我们有一个JSBin演示创建一个组件,用于在播放器顶部显示标题。

此外,有几种方法值得认可:

  • videojs.getComponent(String name):从Video.js检索组件构造函数。
  • videojs.registerComponent(String name, Function Comp): 使用Video.js注册组件构造函数。
  • videojs.extend(Function component, Object properties):提供原型继承。 可用于扩展组件的构造函数,返回具有给定属性的新构造函数。

创建:

// adding a button to the player
var player = videojs('some-video-id');
var Component = videojs.getComponent('Component');
var button = new Component(player); console.log(button.el());
上面的代码将输出
<div class="video-js">
<div class="vjs-button">Button</div>
</div>

将新按钮添加到播放器

// adding a button to the player
var player = videojs('some-video-id');
var button = player.addChild('button'); console.log(button.el());
// 将具有与上一个示例相同的HTML结果

Component Children

再次,请参阅组件API文档,以获得用于管理组件结构的方法的完整细节。

基础示例

当子组件添加到父组件时,Video.js将子元素插入到父元素的元素中。 例如,添加如下组件:

// Add a "BigPlayButton" component to the player. Its element will be appended to the player's element.
player.addChild('BigPlayButton');

结果在DOM中看起来像这样:

<!-- Player Element -->
<div class="video-js">
<!-- BigPlayButton Element -->
<div class="vjs-big-play-button"></div>
</div>

相反,删除子组件将从DOM中删除子组件的元素:

player.removeChild('BigPlayButton');

结果在DOM中看起来像这样:

<!-- Player Element -->
<div class="video-js">
</div>

Using Options

为子构造函数传递选项和为此子组件的子组件传递选项。

var player = videojs('some-vid-id');
var Component = videojs.getComponent('Component');
var myComponent = new Component(player);
var myButton = myComponent.addChild('MyButton', {
text: 'Press Me',
buttonChildExample: {
buttonChildOption: true
}
});

初始化组件时,也可以通过选项添加子项。

注意:包含一个“名称”键,如果两个相同类型的子组件需要不同的选项,则将使用它。

// MyComponent来自上面的例子
var myComp = new MyComponent(player, {
children: ['button', {
name: 'button',
someOtherOption: true
}, {
name: 'button',
someOtherOption: false
}]
});

Event Listening

Using on

var player = videojs('some-player-id');
var Component = videojs.getComponent('Component');
var myComponent = new Component(player);
var myFunc = function() {
var myComponent = this;
console.log('myFunc called');
}; myComponent.on('eventType', myFunc);
myComponent.trigger('eventType');
// logs 'myFunc called'

myFunc的上下文将是myComponent,除非它被绑定。 您可以将侦听器添加到另一个元素或组件。

var otherComponent = new Component(player);

// myComponent/myFunc is from the above example
myComponent.on(otherComponent.el(), 'eventName', myFunc);
myComponent.on(otherComponent, 'eventName', myFunc); otherComponent.trigger('eventName');
// logs 'myFunc called' twice

Using off

var player = videojs('some-player-id');
var Component = videojs.getComponent('Component');
var myComponent = new Component(player);
var myFunc = function() {
var myComponent = this;
console.log('myFunc called');
};
myComponent.on('eventType', myFunc);
myComponent.trigger('eventType');
// logs 'myFunc called' myComponent.off('eventType', myFunc);
myComponent.trigger('eventType');
// does nothing

如果myFunc被排除,则事件类型的所有侦听器都将被删除。 如果eventType被排除,则所有侦听器都将从组件中删除。 您可以使用以删除添加到其他元素或组件的侦听器:

myComponent.on(otherComponent...

在这种情况下,事件类型和侦听器函数都是必需的

var otherComponent = new Component(player);

// myComponent/myFunc is from the above example
myComponent.on(otherComponent.el(), 'eventName', myFunc);
myComponent.on(otherComponent, 'eventName', myFunc); otherComponent.trigger('eventName');
// logs 'myFunc called' twice
myComponent.off(ootherComponent.el(), 'eventName', myFunc);
myComponent.off(otherComponent, 'eventName', myFunc);
otherComponent.trigger('eventName');
// does nothing

Using one

var player = videojs('some-player-id');
var Component = videojs.getComponent('Component');
var myComponent = new Component(player);
var myFunc = function() {
var myComponent = this;
console.log('myFunc called');
};
myComponent.one('eventName', myFunc);
myComponent.trigger('eventName');
// logs 'myFunc called' myComponent.trigger('eventName');
// does nothing

您还可以将监听器添加到仅被触发一次的另一个元素或组件。

var otherComponent = new Component(player);

// myComponent/myFunc is from the above example
myComponent.one(otherComponent.el(), 'eventName', myFunc);
myComponent.one(otherComponent, 'eventName', myFunc); otherComponent.trigger('eventName');
// logs 'myFunc called' twice otherComponent.trigger('eventName');
// does nothing

Using trigger

var player = videojs('some-player-id');
var Component = videojs.getComponent('Component');
var myComponent = new Component(player);
var myFunc = function(data) {
var myComponent = this;
console.log('myFunc called');
console.log(data);
};
myComponent.one('eventName', myFunc);
myComponent.trigger('eventName');
// logs 'myFunc called' and 'undefined' myComponent.trigger({'type':'eventName'});
// logs 'myFunc called' and 'undefined' myComponent.trigger('eventName', {data: 'some data'});
// logs 'myFunc called' and "{data: 'some data'}" myComponent.trigger({'type':'eventName'}, {data: 'some data'});
// logs 'myFunc called' and "{data: 'some data'}"

默认组件树

Video.js播放器的默认组件结构如下所示:

Player  播放器

├── MediaLoader (has no UI)  媒体加载

├── PosterImage  海报图片

├── TextTrackDisplay  文本轨道显示

├── LoadingSpinner 加载旋转器

├── BigPlayButton  大播放按钮

├─┬ ControlBar  控制条

│ ├── PlayToggle  播放切换

│ ├── VolumeMenuButton  声音菜单按钮

│ ├── CurrentTimeDisplay (hidden by default)  当前播放时间

│ ├── TimeDivider (hidden by default)  时间分割器

│ ├── DurationDisplay (hidden by default)  持续播放时间

│ ├─┬ ProgressControl (hidden during live playback)  进度条控制

│ │ └─┬ SeekBar  拖动条

│ │   ├── LoadProgressBar  加载进度条

│ │   ├── MouseTimeDisplay  鼠标时间显示

│ │   └── PlayProgressBar  播放进度条

│ ├── LiveDisplay (hidden during VOD playback) 直播显示

│ ├── RemainingTimeDisplay  剩余时间

│ ├── CustomControlSpacer (has no UI) 自定义控制间隔

│ ├── PlaybackRateMenuButton (hidden, unless playback tech supports rate changes)  播放速率菜单按钮(隐藏,除非回放技术支持速率变化)

│ ├── ChaptersButton (hidden, unless there are relevant tracks)  章节按钮(隐藏,除非有相关轨道)

│ ├── DescriptionsButton (hidden, unless there are relevant tracks)  说明按钮(隐藏,除非有相关轨道)

│ ├── SubtitlesButton (hidden, unless there are relevant tracks)  字幕按钮

│ ├── CaptionsButton (hidden, unless there are relevant tracks)  标题按钮

│ ├── AudioTrackButton (hidden, unless there are relevant tracks)  音频轨道按钮

│ └── FullscreenToggle  全屏切换

├── ErrorDisplay (hidden, until there is an error) 错误(隐藏,直到发生错误)

└── TextTrackSettings 文本轨道设置

特定组件详情

Volume Panel

VolumePanel包括MuteToggle和VolumeControl组件,如果不支持音量更改,它将被隐藏。 VolumePanel有一个重要选项,可以使您的VolumeControl垂直显示在MuteToggle上。 这可以通过传递VolumePanel {inline:false}来设置,因为默认行为是具有{inline:true}的水平VolumeControl。

垂直 VolumeControl的示例

let player = videojs('myplayer', {
controlBar: {
volumePanel: {
inline: false
}
}
});

Text Track Settings

文本轨道设置组件仅在使用模拟文本轨道时可用。

videojs文档翻译Guides-components的更多相关文章

  1. videojs文档翻译-api

    直播流地址 rtmp://live.hkstv.hk.lxdns.com/live/hks API 接口 (一)   Modules  模块 1)         browser :浏览器 2)    ...

  2. videojs文档翻译-Player(v6.0.0-RC.2)

    Player 当使用任何Video.js设置方法初始化视频时,将创建Player类的实例. 创建实例后,可以通过两种方式在全局访问: 调用videojs('example_video_1');直接通过 ...

  3. videojs文档翻译Guides-Plugins

    Video.js Plugins Video.js的一大优势在于其插件生态系统,允许来自世界各地的作者分享他们的视频播放器定制.这包括从最简单的UI调整到新的播放技术和资源处理程序的一切! 因为我们将 ...

  4. videojs文档翻译-EventTarget

    EventTarget new EventTarget()   EventTarget是一个可以与DOM EventTarget具有相同API的类. 它增加了包含冗长功能的缩写功能. 例如:on函数是 ...

  5. videojs文档翻译-SeekBar

    SeekBar 拖动条和进度条的容器. 使用PlayProgressBar作为其栏. 构造函数 new SeekBar(player, optionsopt) 创造此类的实例 Parameters: ...

  6. 一款开源免费跨浏览器的视频播放器--videojs使用介绍

    最近项目中的视频功能,需要做到浏览器全兼容,所以之前用html5实现的视频功能就需要进行改造了.在网上翻了个遍,试来试去,在所有的视频播放器中,就数它最实际了.首先我们来看看它的优点: 1.它是开源免 ...

  7. Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)中一些知识点

    Flume官方文档翻译--Flume 1.7.0 User Guide (unreleased version)(一) Flume官方文档翻译--Flume 1.7.0 User Guide (unr ...

  8. Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)(二)

    Flume官方文档翻译--Flume 1.7.0 User Guide (unreleased version)(一) Logging raw data(记录原始数据) Logging the raw ...

  9. Android API Guides 学习笔记---Application Fundamentals(一)

    今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1.      App ...

随机推荐

  1. TCP/IP协议 (图解+秒懂+史上最全)

    文章很长,建议收藏起来,慢慢读! 疯狂创客圈为小伙伴奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : <Netty Zookeeper Redis 高并发实战> 面试必备 + 大厂必备 ...

  2. Spring Boot WebFlux-04——WebFlux 整合 Thymeleaf

    第04课:WebFlux 整合 Thymeleaf 上一篇介绍的是用 MongoDB 来实现 WebFlux 对数据源的操作,那么有了数据需要渲染到前台给用户展示,这就是本文关心的 View 层,Vi ...

  3. 【无线通信篇01 | Zstack协议栈】CC2530 Zigbee Zstack协议栈组网项目及详细讲解篇

    演示视频:https://www.bilibili.com/video/BV1Ew411o7Fp 物联网无线通信技术,ZigBee无线传感网络 CC2530最大的特点就是一个拥有无线收发器(RF)的单 ...

  4. 本地SQL Server怎么连接服务器上的数据库

    在阿里云的安全组规则中的入方向加上端口1433就好了,首先得要有这个,其他的都是后话

  5. Golang通过反射拼接一个结构体所有字段

    golang通过反射拼接一个结构体所有字段 需求 将一个结构体所有字段以"|"连接拼接成字符串 golang 不同类型拼接成string使用Sprintf比较麻烦,如果一个结构体有 ...

  6. ClickHouse源码笔记6:探究列式存储系统的排序

    分析完成了聚合以及向量化过滤,向量化的函数计算之后.本篇,笔者将分析数据库的一个重要算子:排序.让我们从源码的角度来剖析ClickHouse作为列式存储系统是如何实现排序的. 本系列文章的源码分析基于 ...

  7. 10年程序员的编程语言感受与Go的结缘

    因为小编最近在写两套教程,分别是Java语言基础教程和Go语言的基础教程,并且这 2 门语言,小编在实际的工作中也都有用过 而且 www.helloworld.net 社区的后台,就是用Go语言写的, ...

  8. Redis 底层数据结构之整数集合

    文章参考:<Redis 设计与实现>黄建宏 整数集合 整数集合时集合键的底层实现之一,当一个集合只包含整数值元素,并且这个集合数量不多时,就会使用整数集合 typedef struct i ...

  9. PostgreSQL用户和权限问题

    PostgreSQL用户 其实用户和角色都是角色,只是用户是具有登录权限的角色. 创建用户 create user sonar password '123'; 删除用户 drop user sonar ...

  10. Python管道进行数据的吞吐处理

    import multiprocessing import random import time import datetime import struct import os import getF ...