From 43b215f1cb16f1edba8dafaf867a6a140617cfc5 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 16 Sep 2014 13:55:55 -0400 Subject: [PATCH 1/3] 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. --- src/js/player.js | 2 ++ 1 file changed, 2 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(); } }; From 8a6ab3c906949086804274a949341d581645cc89 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 16 Sep 2014 14:30:47 -0400 Subject: [PATCH 2/3] Add tests for onEnded change --- test/unit/player.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/unit/player.js b/test/unit/player.js index fe6b8b6db8..00c163d8d4 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'); +}); From 7477b657480d1380cd7677ce4474cc6f232933ee Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 16 Sep 2014 14:56:34 -0400 Subject: [PATCH 3/3] Appease jshint. --- test/unit/player.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/player.js b/test/unit/player.js index 00c163d8d4..66f7e1d71f 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -625,7 +625,7 @@ test('pause is called when player ended event is fired and player is not paused' pauses = 0; player.paused = function() { return false; - } + }; player.pause = function() { pauses++; }; @@ -639,7 +639,7 @@ test('pause is not called if the player is paused and ended is fired', function( pauses = 0; player.paused = function() { return true; - } + }; player.pause = function() { pauses++; };