我在網上隨處看,但我找不到任何明確的文檔或一些示例來創建我的verySimplePlugin videoJS 5(因爲它使用ES6)。VideoJS 5插件添加按鈕
我只是想添加一個按鈕旁邊的大播放按鈕...有人可以幫助我嗎?
謝謝...
PS:我使用它angularJS,但我想這不可能有問題
我在網上隨處看,但我找不到任何明確的文檔或一些示例來創建我的verySimplePlugin videoJS 5(因爲它使用ES6)。VideoJS 5插件添加按鈕
我只是想添加一個按鈕旁邊的大播放按鈕...有人可以幫助我嗎?
謝謝...
PS:我使用它angularJS,但我想這不可能有問題
這是我創建了一個簡單的按鈕插件videojs 5:
(function() {
var vsComponent = videojs.getComponent('Button');
// Create the button
videojs.SampleButton = videojs.extend(vsComponent, {
constructor: function() {
vsComponent.call(this, videojs, null);
}
});
// Set the text for the button
videojs.SampleButton.prototype.buttonText = 'Mute Icon';
// These are the defaults for this class.
videojs.SampleButton.prototype.options_ = {};
// videojs.Button uses this function to build the class name.
videojs.SampleButton.prototype.buildCSSClass = function() {
// Add our className to the returned className
return 'vjs-mute-button ' + vsComponent.prototype.buildCSSClass.call(this);
};
// videojs.Button already sets up the onclick event handler, we just need to overwrite the function
videojs.SampleButton.prototype.handleClick = function(e) {
// Add specific click actions here.
console.log('clicked');
};
videojs.SampleButton.prototype.createEl = function(type, properties, attributes) {
return videojs.createEl('button', {}, {class: 'vjs-mute-btn'});
};
var pluginFn = function(options) {
var SampleButton = new videojs.SampleButton(this, options);
this.addChild(SampleButton);
return SampleButton;
};
videojs.plugin('sampleButton', pluginFn);
})();
你可以用這種方式:
var properties = { "plugins": { "muteBtn": {} } }
var player = videojs('really-cool-video', properties , function() { //do something cool here });
或者這樣說:
player.sampleButton()
這是你如何可以添加下載按鈕來控制欄的末尾沒有任何插件或其他複雜的代碼:
var vjsButtonComponent = videojs.getComponent('Button');
videojs.registerComponent('DownloadButton', videojs.extend(vjsButtonComponent, {
constructor: function() {
vjsButtonComponent.apply(this, arguments);
},
handleClick: function() {
document.location = '/path/to/your/video.mp4'; //< there are many variants here so it is up to you how to get video url
},
buildCSSClass: function() {
return 'vjs-control vjs-download-button';
},
createControlTextEl: function (button) {
return $(button).html($('<span class="glyphicon glyphicon-download-alt"></span>').attr('title', 'Download'));
}
}));
videojs(
'player-id',
{fluid: true},
function() {
this.getChild('controlBar').addChild('DownloadButton', {});
}
);
我用「glyphicon glyphicon下載-ALT」圖標和標題所以它適合玩家控制條的造型。
工作原理:
後注:也應該有辦法把你的按鈕放在'controlBar'的任何地方,但我還沒有想出如何,因爲下載按鈕在控制條的末端是好的