videojs 控制條上添加自定義圖標和相關的事件

代碼

<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet">
<!-- ...videojs樣式代碼等 -->
<style>
    /*   step-backward 48   backward 49 forward 50 step-forward 51     */
    .video-js .vjs-custom-control .vjs-icon-placeholder:before{
        font-family: 'Font Awesome 5 Free';
        font-weight: 600;
        content: '\f049'; 
    }
</style>

 (function (vjs) {
      var customPlugin = function (options) {
      
          var player = this;
          
          // 方式多次加載,再銷燬之前
          if (!player.el()) {
              return;
          }
          
          var video = player.player().el().getElementsByTagName('video')[0];


          var customButtom = videojs.getComponent("Button");
          var pipButton = videojs.extend(customButtom, {
              constructor: function (player, options) {

                  customButtom.call(this, player, options);
                  this.controlText("提示文字");

              },
              handleClick: function () {

                  console.log(options) //{ name: 'customName' }

              },
              buildCSSClass: function () {

                  return "vjs-custom-control vjs-control vjs-button";

              }
          });
          videojs.registerComponent("customButtom", pipButton);

          player.on('loadstart', function () {

              var customButtomBtn = player.controlBar.addChild('customButtom', {});
              player.controlBar.el().insertBefore(customButtomBtn.el(), player.controlBar.fullscreenToggle.el());

          });


      };
      vjs.registerPlugin('customPlugin', customPlugin);
  })(window.videojs);
  
  // ...
  var src = 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8';
  videojs("liveVideo", {
     language: 'zh-CN',
     // playbackRates: [0.25, 0.5, 1, 1.5, 2],
     sources: [{
         src: src,
         type: 'application/x-mpegURL'
     }],
     plugins: {
     	// 添加buton
         customPlugin: { name: 'customName' }
     }
 }, function onPlayerReady() {
     var w = $("#video").width();
     var h = $("#video").height();
     $("#liveVideo").css({ "width": w, "height": h });
     this.poster('./init.gif')
     this.play();
 })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章