From 043b0f82a98227e1af56cfff124935d45ab9301d Mon Sep 17 00:00:00 2001 From: anoosi Date: Sun, 8 Oct 2017 09:22:02 +0300 Subject: [PATCH] add button to videojs on/off --- example-videojs/videojs.libass.js | 45 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/example-videojs/videojs.libass.js b/example-videojs/videojs.libass.js index 6f8d023..e4e396b 100644 --- a/example-videojs/videojs.libass.js +++ b/example-videojs/videojs.libass.js @@ -10,7 +10,11 @@ lib = null, render = null, track = null, - clock = null; + clock = null, + AssButton = null, + AssButtonInstance = null, + OverlayComponent = null, + VjsButton = null; if (!options.src) { return; @@ -222,11 +226,42 @@ lastTime = 0; }); - player.ready(function () { + // Visibility Toggle Button + if (!options.hasOwnProperty('button') || options.button) { + VjsButton = videojs.getComponent('Button'); + AssButton = videojs.extend(VjsButton, { + constructor: function (player, options) { + options.name = options.name || 'assToggleButton'; + VjsButton.call(this, player, options); + this.controlText('Subtitle ASS'); + }, + buildCSSClass: function () { + var classes = VjsButton.prototype.buildCSSClass.call(this); + return 'vjs-subtitles-button ' + classes; + }, + handleClick: function () { + if (!this.hasClass('inactive')) { + this.addClass('inactive'); + overlay.style.visibility = "hidden"; + } else { + this.removeClass('inactive'); + overlay.style.visibility = "visible"; + } + } + }); + + player.ready(function () { ass_set_frame_size(render, getVideoWidth(), getVideoHeight()); console.log(getVideoWidth() + 'x' + getVideoHeight()); - }); - } + AssButtonInstance = new AssButton(player, options); + player.controlBar.addChild(AssButtonInstance); + player.controlBar.el().insertBefore( + AssButtonInstance.el(), + player.controlBar.getChild('customControlSpacer').el().nextSibling + ); + }); + } + } videojs.plugin('ass', libassjs); -}(window.videojs, window.libjass)); \ No newline at end of file +}(window.videojs, window.libjass));