为 VideoJS 5 编写插件

Write plugin for VideoJS 5

本文关键字:插件 VideoJS      更新时间:2023-09-26

当我尝试使用最新版本的videojs 5时,以下代码不再有效。我正在尝试编写一个videojs插件,但是videojs 5使用ecmascript 6,这对我来说是新的。任何帮助都值得赞赏。

   videojs.SharingButton = videojs.Button.extend({
    /** @constructor */
    init: function(player, options){
        videojs.Button.call(this, player, options);
        this.player = player;
    }
});
videojs.SharingButton.prototype.createEl = function(tagName,options) {
    return videojs.Component.prototype.createEl(tagName,{
        className: this.buildCSSClass(),
        innerHTML: '',
        role: 'button',
        'aria-live': 'polite', // let the screen reader user know that the text of the button may change
        tabIndex: 0
    });
}
videojs.SharingButton.prototype.buttonText = 'Share Video';
videojs.SharingButton.prototype.options_ = {};
videojs.SharingButton.prototype.buildCSSClass = function(){
    return 'vjs-sharing-control ';
};
嗨,

我遇到了同样的问题,请替换此代码

videojs.SharingButton = videojs.Button.extend({

var SharingButton = videojs.getComponent('Button');
videojs.SharingButton = videojs.extend(SharingButton , {...});
videojs.registerComponent('SharingButton', SharingButton);
var myButton = myPlayer.addChild('SharingButton');
如果要添加不是玩家元素直接子元素的组件,

则必须爬上子元素并添加组件。喜欢:

parentComponent = myPlayer.getChild('component1').getChild('component2')...
parentComponent.addChild('SharingButton')

请注意,播放器组件必须以小写形式开头,例如 controlBar .

在此链接中找到组件树。

随着 5.0 版的构建,已经进行了许多更改(请参阅此链接),不幸的是,大多数 videojs 插件都没有更新其代码! 主题之一是社交按钮共享