How to add new components(buttons) onto video.js?

回眸只為那壹抹淺笑 提交于 2019-12-24 14:44:28

问题


My question is how to add new components(control buttons) on video.js player.

For example, adding a button to allow to change the video playback rate.

Giving a simple example would be much helpful. Thank you very much.


回答1:


It doesn't appear VideoJS Supports playback-rate directly, but from my understanding it's just a fancy wrapper for an HTML5 Video Element.

According to this stack overflow question/answer you can change the playback rate of HTML5 video directly on the DOM Element as referenced by the W3C HTML5 Video Wiki Entry.

You probably will have to side-step VideoJS to do this as the support doesn't look baked in. Also, there may be issues between browsers over support of this attribute.

As for simply adding controls, VideoJS implements a Javascript API you can use to control the element but it seems pretty limited to the most basic of controls (play/pause/goto/fullscreen/etc...)

The default controls the player has don't seem to be greatly customizable so if you wish to provide a clearer experience, you can probably disable the in-video controls and re-implement your own in html/dom/js underneath the video element.

Example:

With some really simple html & Javascript, you can wire up some simple controls.

HTML:

<video id="Vid" ...>
</video>
<div id="Controls">
 <a id="Play" href="#Play">Play</a> - <a id="Pause" href="#Pause">Pause</a>
</div>

JS:

_V_("Vid").ready(function() {
  var player = this;

  var playbutton = document.getElementById("Play");
  var pausebutton = document.getElementById("Pause");

  playbutton.onclick = function(event) {
    player.play();
  };

  pausebutton.onclick = function(event) {
    player.pause();
  };

});



回答2:


After searching for this myself, I have found a similar thing happening at the very bottom of the tracks.js file.

// Add Buttons to controlBar
_V_.merge(_V_.ControlBar.prototype.options.components, {
   "subtitlesButton": {},
   "captionsButton": {},
   "chaptersButton": {}
});

From tracks.js https://github.com/videojs/video.js/blob/master/src/js/tracks.js



来源:https://stackoverflow.com/questions/10711512/how-to-add-new-componentsbuttons-onto-video-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!