Skip to content

Commit

Permalink
fixes #1512, fixes #1507
Browse files Browse the repository at this point in the history
On ended, pause player if not paused or looping
IE11 (and maybe other browsers as well) only fire 'ended' event when the
video ends and doesn't fire pause. This makes IE11 not reset it's state
into a paused state that allows a user to replay immediately. However, a
two clicks on the play/pause button will allow you to replay.
In Chrome, we get first a pause event and then an ended event. When
'loop' is set, neither the last pause nor ended fire.
In the flash tech, the pause and ended events fire like in chrome in all
browsers.

Add tests for onEnded change

Appease jshint.
  • Loading branch information
gkatsev authored and heff committed Sep 16, 2014
1 parent 18965bb commit 53ea60c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/js/player.js
Expand Up @@ -511,6 +511,8 @@ vjs.Player.prototype.onEnded = function(){
if (this.options_['loop']) {
this.currentTime(0);
this.play();
} else if (!this.paused()) {
this.pause();
}
};

Expand Down
28 changes: 28 additions & 0 deletions test/unit/player.js
Expand Up @@ -618,3 +618,31 @@ test('should clear pending errors on disposal', function() {
}
ok(true, 'did not throw an error after disposal');
});

test('pause is called when player ended event is fired and player is not paused', function() {
var video = document.createElement('video'),
player = PlayerTest.makePlayer({}, video),
pauses = 0;
player.paused = function() {
return false;
};
player.pause = function() {
pauses++;
};
player.trigger('ended');
equal(pauses, 1, 'pause was called');
});

test('pause is not called if the player is paused and ended is fired', function() {
var video = document.createElement('video'),
player = PlayerTest.makePlayer({}, video),
pauses = 0;
player.paused = function() {
return true;
};
player.pause = function() {
pauses++;
};
player.trigger('ended');
equal(pauses, 0, 'pause was not called when ended fired');
});

0 comments on commit 53ea60c

Please sign in to comment.