首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VideoJS如何获取当前时间

VideoJS如何获取当前时间
EN

Stack Overflow用户
提问于 2016-02-17 10:25:55
回答 1查看 486关注 0票数 0

我在video.js中检索有关video.js的信息时遇到了问题。我有下一个代码:

Player.js

代码语言:javascript
复制
(function(){

  PlayerGam = function( container ){

    this._video = new videojs( container );

    _init.apply( this );
  };

  var _init = function(){
    this._video.on( 'ended', _onEnded );
    this._video.on( 'loadeddata', _onLoadedData );
    this._video.on( 'timeupdate', _onTimeUpdate );
    this._video.on( 'useractive', _onUserActive );
    this._video.on( 'userinactive', _onUserInactive );
    this._video.on( 'volumechange', _onVolumeChange );
  };

  var _onEnded = function(evt){
    console.log( '[Video][Gam] VideoJS: Ended video ' + evt );
  };

  var _onLoadedData = function(evt){
    console.log( '[Video][Gam] VideoJS: Loaded Data ' + evt );
  };

  var _onTimeUpdate = function(evt){
    console.log( '[Video][Gam] VideoJS: Time update ' + this._video.currentTime() );
  };

  var _onUserActive = function(evt){
    console.log( '[Video][Gam] videoJS: User active ' + evt );
  };

  var _onUserInactive = function(evt){
    console.log( '[Video][Gam] VideoJS: User inactive ' + evt );
  };

  var _onVolumeChange = function(evt){
    console.log( '[Video][Gam] VideoJS: Volume Change ' + evt );
  };

})();

instance.js

代码语言:javascript
复制
(function(){

  var instance = new PlayerGam( 'example_video' );

})();

代码语言:javascript
复制
<!doctype html>
<html>
  <head>
    <title> VideoJS - Test 3 </title>

    <link href="./styles/video-js.css" rel="stylesheet">
  </head>
  <body>

    <div id="container">
      <video id="example_video" class="video-js vjs-default-skin" controls width="640" height="380">
        <source src="http://rmcdn.2mdn.net/Demo/vast_inspector/android.mp4" type="video/mp4" ></source>
      </video>
    </div>

    <script src="./js/video.js" type="text/javascript" ></script>
    <script src="./js/player_gam.js" type="text/javascript" ></script>
    <script src="./js/instance.js" type="text/javascript" ></script>
  </body>
</html>

下一个错误出现在我的浏览器控制台上:

代码语言:javascript
复制
TypeError: this._video is undefined


console.log( '[Video][Gam] VideoJS: Time update ' + this._video.currentTime() )

任何帮助都是有用的,

谢了贾斯特。

EN

回答 1

Stack Overflow用户

发布于 2016-02-17 17:23:07

在事件回调中,this将是播放器。您应该使用this.currentTime()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35453981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档