videojs文档翻译Guides-components
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的更多相关文章
- videojs文档翻译-api
直播流地址 rtmp://live.hkstv.hk.lxdns.com/live/hks API 接口 (一) Modules 模块 1) browser :浏览器 2) ...
- videojs文档翻译-Player(v6.0.0-RC.2)
Player 当使用任何Video.js设置方法初始化视频时,将创建Player类的实例. 创建实例后,可以通过两种方式在全局访问: 调用videojs('example_video_1');直接通过 ...
- videojs文档翻译Guides-Plugins
Video.js Plugins Video.js的一大优势在于其插件生态系统,允许来自世界各地的作者分享他们的视频播放器定制.这包括从最简单的UI调整到新的播放技术和资源处理程序的一切! 因为我们将 ...
- videojs文档翻译-EventTarget
EventTarget new EventTarget() EventTarget是一个可以与DOM EventTarget具有相同API的类. 它增加了包含冗长功能的缩写功能. 例如:on函数是 ...
- videojs文档翻译-SeekBar
SeekBar 拖动条和进度条的容器. 使用PlayProgressBar作为其栏. 构造函数 new SeekBar(player, optionsopt) 创造此类的实例 Parameters: ...
- 一款开源免费跨浏览器的视频播放器--videojs使用介绍
最近项目中的视频功能,需要做到浏览器全兼容,所以之前用html5实现的视频功能就需要进行改造了.在网上翻了个遍,试来试去,在所有的视频播放器中,就数它最实际了.首先我们来看看它的优点: 1.它是开源免 ...
- 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 ...
- Flume官方文档翻译——Flume 1.7.0 User Guide (unreleased version)(二)
Flume官方文档翻译--Flume 1.7.0 User Guide (unreleased version)(一) Logging raw data(记录原始数据) Logging the raw ...
- Android API Guides 学习笔记---Application Fundamentals(一)
今天开始学习google官网上的API guides ,主要读了Application Fundamentals这一章节,此章节介绍了一个App的基本组成,共包括四大部分内容. 1. App ...
随机推荐
- 既然有 HTTP 请求,为什么还要用 RPC 调用?
首先,实名赞扬题主的问题.这个问题非常好. 其次,实名反对各个上来就讲RPC好而HTTP不好的答案.因为,题主的观点非常对. HTTP协议,以其中的Restful规范为代表,其优势很大.它可读性好,且 ...
- csp-s模拟测试42「世界线·时间机器·密码」
$t3$不会 世界线 题解 题目让求的就是每个点能到点的数量$-$出度 设每个点能到的点为$f[x]$ 则$f[x]=x \sum\limits_{y}^{y\in son[x]} U f[y]$ 用 ...
- 重新整理 .net core 实践篇—————仓储层的具体实现[二十七]
前言 简单整理一下仓储层. 正文 在共享层的基础建设类库中: /// <summary> /// 泛型仓储接口 /// </summary> /// <typeparam ...
- Springboot WebFlux集成Spring Security实现JWT认证
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 简介 在之前的文章<Springboot集成Spring Security实现JWT认证>讲解了如何在传统 ...
- 用VSCode终端实现重定向比较程序输出和正确输出
在刷 OJ 题目或者进行编程考试或比赛时,经常需要对编写好的程序进行测试,即运行编写好的程序,输入样例输入或者自己编写的输入数据,查看程序输出结果和样例输出或者正确输出是否一致.这种方法有很多弊端,当 ...
- mysql字符集utf8和utf8mb4区别
1.起因 公司游戏项目上线第一天,出现单个区服异常宕机的问题,根据日志排查下来,连接数据的时候报错,后面排查是因为有玩家插入Emoji 等表情导致无法存储如数据库,数据库字符集编码为utf8,后续改成 ...
- 乘风破浪,Windows11设计和开发指导,全新图标字体和云母材质
Windows11全新的布局设计 Windows 11全新的布局设计已设计为支持现代应用体验.渐进的圆角.嵌套元素和一致的排水沟相结合,营造出柔和.平静.平易近人的效果,强调目的的统一和易用性. ht ...
- 40、Nginx 配置支持 WAF
40.1 waf说明 1 WAF(Web Application Firewall),中文名叫做"Web应用防火墙". 2 WAF的定义是这样的:Web应用防火墙是通过执行一系列针 ...
- 33、jQuery介绍
33.1.jQuery是什么: (1)jQuery由John Resig创建,至今已吸引了来自世界各地的众多 javascript 高手加入其team. (2)jQuery是继prototype之后又 ...
- scrapy入门到放弃02:整一张架构图,开发一个程序
前言 Scrapy开门篇写了一些纯理论知识,这第二篇就要直奔主题了.先来讲讲Scrapy的架构,并从零开始开发一个Scrapy爬虫程序. 本篇文章主要阐述Scrapy架构,理清开发流程,掌握基本操作. ...