1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-19 10:54:16 +02:00

enableUserActivity on component

disableUserActivity on MediaTechController and Player.
MediaTechController does it manually.
This commit is contained in:
Gary Katsevman 2014-02-05 20:41:52 -05:00
parent a7d624affe
commit 26c8d3f92c
3 changed files with 51 additions and 25 deletions

View File

@ -66,22 +66,7 @@ vjs.Component = vjs.CoreObject.extend({
// Don't want to trigger ready here or it will before init is actually
// finished for all children that run this constructor
var touchmove = false;
this.on('touchstart', function() {
touchmove = false;
});
this.on('touchmove', vjs.bind(this, function() {
if (this.listenToTouchMove) {
this.player_.reportUserActivity();
}
touchmove = true;
}));
this.on('touchend', vjs.bind(this, function(event) {
if (!touchmove) {
this.player_.reportUserActivity();
}
}));
this.enableUserActivity();
}
});
@ -869,8 +854,6 @@ vjs.Component.prototype.emitTapEvents = function(){
// When the touch ends, measure how long it took and trigger the appropriate
// event
this.on('touchend', function(event) {
event.stopImmediatePropagation();
// Proceed only if the touchmove/leave/cancel event didn't happen
if (couldBeTap === true) {
// Measure how long the touch lasted
@ -885,3 +868,31 @@ vjs.Component.prototype.emitTapEvents = function(){
}
});
};
vjs.Component.prototype.enableUserActivity = function() {
var touchmove = false;
this.enableUserActivity.touchstart = function() {
touchmove = false;
};
this.enableUserActivity.touchmove = vjs.bind(this, function() {
this.player_.reportUserActivity();
touchmove = true;
});
this.enableUserActivity.touchend = vjs.bind(this, function() {
if (!touchmove) {
this.player_.reportUserActivity();
}
});
this.on('touchstart', this.enableUserActivity.touchstart);
this.on('touchmove', this.enableUserActivity.touchmove);
this.on('touchend', this.enableUserActivity.touchend);
};
vjs.Component.prototype.disableUserActivity = function() {
this.off('touchstart', this.enableUserActivity.touchstart);
this.off('touchmove', this.enableUserActivity.touchmove);
this.off('touchend', this.enableUserActivity.touchend);
};

View File

@ -15,6 +15,7 @@ vjs.MediaTechController = vjs.Component.extend({
vjs.Component.call(this, player, options, ready);
this.initControlsListeners();
this.disableUserActivity();
}
});
@ -60,7 +61,8 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){
};
vjs.MediaTechController.prototype.addControlsListeners = function(){
var preventBubble, userWasActive;
var userWasActive,
touchmove = false;
// Some browsers (Chrome & IE) don't trigger a click on a flash swf, but do
// trigger mousedown/up.
@ -82,14 +84,29 @@ vjs.MediaTechController.prototype.addControlsListeners = function(){
this.on('touchstart', function(event) {
// Stop the mouse events from also happening
event.preventDefault();
userWasActive = this.player().userActive();
touchmove = false;
});
this.on('touchmove', function(event) {
touchmove = true;
})
this.on('touchend', function(event) {
if (userWasActive) {
this.player().reportUserActivity();
}
if (!touchmove) {
this.player().userActive(!this.player().userActive());
}
});
// Turn on component tap events
this.emitTapEvents();
//this.emitTapEvents();
// The tap listener needs to come after the touchend listener because the tap
// listener cancels out any reportedUserActivity when setting userActive(false)
this.on('tap', this.onTap);
//this.on('tap', this.onTap);
};
/**
@ -134,10 +151,7 @@ vjs.MediaTechController.prototype.onClick = function(event){
*/
vjs.MediaTechController.prototype.onTap = function(){
var userActivity = this.player().userActive();
if (userActivity) {
this.player().userActive(!userActivity);
}
this.player().userActive(!this.player().userActive());
};
vjs.MediaTechController.prototype.features = {

View File

@ -106,6 +106,7 @@ vjs.Player = vjs.Component.extend({
}
this.listenForUserActivity();
this.disableUserActivity();
}
});