Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On ended, pause player if not paused or looping #1507

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');
});