我在video.js中检索有关currentMilis的信息时遇到问题。我有下一个代码:
Player.js
(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
(function(){
var instance = new PlayerGam( 'example_video' );
})();
HTML
<!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>
我的浏览器控制台上出现了下一个错误:
TypeError: this._video is undefined
console.log( '[Video][Gam] VideoJS: Time update ' + this._video.currentTime() )
任何帮助都可能有用,
谢谢,Jaster。
答案 0 :(得分:0)
在事件回调中,this
将成为玩家。您应该使用this.currentTime()
。