Video.js 指南
这些指南涵盖了 Video.js 用户的各种主题
Video.js 7 到 8 迁移
本指南描述了 Video.js 7 和 Video.js 8 之间向后不兼容的更改,以及如何在需要时迁移您的实现。
IE11 支持
Video.js 8 移除了对 IE11 的支持。在 IE11 中尝试使用 Video.js 8 将会导致错误。此处没有迁移路径;因此,如果您必须支持 IE11,请使用较旧版本的 Video.js。
移除项
videojs.extend()
videojs.extend()
函数已从 Video.js 8 中移除。
Video.js 现在内部使用原生 ES6 类,而 extend()
函数只适用于普通函数原型。它不适用于 ES6 类,因此已被移除。
最基本来说,使用 extend()
创建组件的旧方法是
const Component = videojs.getComponent('Component');
const MyComponent = videojs.extend(Component, {
constructor: function(player, options) {
Component.call(this, player, options);
}
});
videojs.registerComponent('MyComponent', MyComponent);
今后,只支持 ES6 类。等效代码如下:
const Component = videojs.getComponent('Component');
class MyComponent extends Component {
constructor(player, options) {
super(player, options);
}
}
videojs.registerComponent('MyComponent', MyComponent);
注意: 还需要提及的是,已经转译过的原生类将不适用于原生
extend
!例如,当前的插件构建工具会将class
转译为普通的构造函数,而这些构造函数无法被extend
。
firstplay
事件
firstplay
事件已从 Video.js 8 中移除。
不再监听 firstplay
事件,而是使用 one()
将回调绑定到 play
事件的首次发生,如下所示:
player.ready(() => {
player.one('play', callback);
});
将 ARIA 特性设置为属性
在 Video.js 的早期版本中,您可以在 createEl()
的第二个参数中使用 DOM 属性和特性名称来调用其各种变体。
虽然在大多数情况下属性与特性之间存在一对一映射,但通过此机制设置 ARIA 特性名称(例如 aria-label
与 ariaLabel
)已不再受支持。
// NO LONGER SUPPORTED!!!
videojs.dom.createEl('div', {id: 'example', 'aria-label': 'My Label'});
尝试在 createEl()
函数的第二个参数中设置这些类型的特性,仍然会在 DOM 对象上设置同名属性,但 它们不会设置特性或标准 DOM 属性。
相反,这些必须使用第三个参数进行设置,如下所示:
videojs.dom.createEl('div', {id: 'example'}, {'aria-label': 'My Label'});
或者,ARIA 特性可以以其属性名称形式进行设置:
videojs.dom.createEl('div', {id: 'example', ariaLabel: 'My Label'});
弃用项
许多函数在 Video.js 8(或更早版本)中已被弃用。以下是这些函数的列表。
新弃用函数
这些函数在 Video.js 8 中被新弃用,但应替换它们以抑制弃用警告,并为 Video.js 9 做准备。
弃用函数 | 请改用... |
---|---|
videojs.bind | 原生 Function.prototype.bind |
videojs.computedStyle | videojs.dom.computedStyle |
videojs.createTimeRange | videojs.time.createTimeRanges |
videojs.createTimeRanges | videojs.time.createTimeRanges |
videojs.defineLazyProperty | videojs.obj.defineLazyProperty |
videojs.formatTime | videojs.time.formatTime |
videojs.isCrossOrigin | videojs.url.isCrossOrigin |
videojs.mergeOptions | videojs.obj.merge |
videojs.parseUrl | videojs.url.parseUrl |
videojs.resetFormatTime | videojs.time.resetFormatTime |
videojs.setFormatTime | videojs.time.setFormatTime |
这些函数在首次使用时都会记录弃用警告……但只在首次使用时,以免过于嘈杂!
这些弃用函数将在 Video.js 9.0 中移除!
旧弃用函数
仍有一些较旧的函数可用,但已被弃用:
弃用函数 | 请改用... |
---|---|
videojs.addClass | videojs.dom.addClass |
videojs.appendContent | videojs.dom.appendContent |
videojs.createEl | videojs.dom.createEl |
videojs.emptyEl | videojs.dom.emptyEl |
videojs.getAttributes | videojs.dom.getAttributes |
videojs.hasClass | videojs.dom.hasClass |
videojs.insertContent | videojs.dom.insertContent |
videojs.isEl | videojs.dom.isEl |
videojs.isTextNode | videojs.dom.isTextNode |
videojs.plugin | videojs.registerPlugin |
videojs.removeClass | videojs.dom.removeClass |
videojs.setAttributes | videojs.dom.setAttributes |
videojs.toggleClass | videojs.dom.toggleClass |
这些弃用函数将在 Video.js 9.0 中移除!