【问题标题】:How to add annotations in video using video.js如何使用 video.js 在视频中添加注释
【发布时间】:2014-03-28 06:57:43
【问题描述】:

是否可以使用Video.js在我的视频中添加注释?

下面是我的作品

<link href="http://vjs.zencdn.net/4.4/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.4/video.js"></script>

<video id="my_video_1" class="video-js vjs-default-skin" controls
 preload="auto" width="640" height="264" poster="my_video_poster.png"
 data-setup="{}">
 <source src="my_video.mp4" type='video/mp4'>
 <source src="my_video.webm" type='video/webm'>
</video>

【问题讨论】:

标签: annotations html5-video video.js


【解决方案1】:
<script>

  var Plugin = videojs.getPlugin('plugin');
  var ExamplePlugin = videojs.extend(Plugin, {

    constructor: function(player, options) {
      Plugin.call(this, player, options);
        player.on('timeupdate', function(){

  var Component = videojs.getComponent('Component');
        var TitleBar = videojs.extend(Component, {
          constructor: function(player, options) {
            Component.apply(this, arguments);
            if (options.text) 
            {
              this.updateTextContent(options.text);
            }
          },
          createEl: function() {
            return videojs.createEl('div', {
              className: 'vjs-title-bar'
            });
          },
          updateTextContent: function(text) {

            if (typeof text !== 'string') {
              text = 'hello world';
            }
            videojs.emptyEl(this.el());
            videojs.appendContent(this.el(), text);
          }
        });
        videojs.registerComponent('TitleBar', TitleBar);
        var player = videojs('my-video');
        player.addChild('TitleBar', {text: 'hellow people!'});


          });
      }
    });

  videojs.registerPlugin('examplePlugin', ExamplePlugin);
  videojs('#my-video', {}, function(){
  this.examplePlugin();
  });
  </script 

</html>

//复制并粘贴这段代码,它肯定会工作。

【讨论】:

  • ">" 我错过了这个。
  • 您好,欢迎来到 stackoverflow,感谢您的回答。虽然这段代码可能会回答这个问题,但您是否可以考虑添加一些解释来说明您解决了什么问题,以及您是如何解决的?这将有助于未来的读者更好地理解您的答案并从中学习。此外,在修改您的答案时,请考虑 editing 您的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多