From 53ea60cd06ce1fb8d1a9b216d2636c8cdb77970d Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 16 Sep 2014 13:55:55 -0400 Subject: [PATCH] fixes #1512, fixes #1507 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. --- src/js/player.js | 2 ++ test/unit/player.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/js/player.js b/src/js/player.js index f98aea2633..39d88d8049 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -511,6 +511,8 @@ vjs.Player.prototype.onEnded = function(){ if (this.options_['loop']) { this.currentTime(0); this.play(); + } else if (!this.paused()) { + this.pause(); } }; diff --git a/test/unit/player.js b/test/unit/player.js index fe6b8b6db8..66f7e1d71f 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -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'); +});