From 6049d6780478d730ec5b64d9105658949b46de65 Mon Sep 17 00:00:00 2001 From: Timothy Drews Date: Fri, 11 Sep 2015 13:08:21 -0700 Subject: [PATCH] Re-allow pausing while rewinding. This fixes a regression and adds more integration tests. Closes #130 Change-Id: Idd386931ae6d9f37052f24438ebcba10774e3451 --- lib/player/player.js | 7 ++++ spec/player_integration.js | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/lib/player/player.js b/lib/player/player.js index 19018db4f9..84935197c3 100644 --- a/lib/player/player.js +++ b/lib/player/player.js @@ -468,6 +468,7 @@ shaka.player.Player.prototype.onPause_ = function(event) { if (!isNaN(elapsed)) { this.stats_.logPlayTime(elapsed); } + this.cancelRewindTimer_(); }; @@ -935,9 +936,15 @@ shaka.player.Player.prototype.cancelWatchdogTimer_ = function() { shaka.player.Player.prototype.onRewindTimer_ = function(startVideoTime, startWallTime, rate) { shaka.asserts.assert(rate < 0); + shaka.asserts.assert(!this.video_.paused); + this.rewindTimer_ = null; var offset = ((Date.now() - startWallTime) / 1000) * rate; + + // For live content the seek start time may increase over time, so to avoid + // any races between this function and onSeekRangeChanged_() use a larger + // fudge factor. var fudge = this.isLive() ? 1 : 0.05; if (this.video_.currentTime < this.seekRangeStart_ + fudge) { diff --git a/spec/player_integration.js b/spec/player_integration.js index e74fdf321b..753643a92a 100644 --- a/spec/player_integration.js +++ b/spec/player_integration.js @@ -779,6 +779,78 @@ describe('Player', function() { done(); }); }); + + it('pauses while rewinding', function(done) { + var timestamp; + player.setPlaybackStartTime(45); + player.load(newSource(plainManifest)).then(function() { + video.play(); + return waitForTargetTime(video, eventManager, 49, 6); + }).then(function() { + player.setPlaybackRate(-1.0); + return delay(2.0); + }).then(function() { + video.pause(); + timestamp = video.currentTime; + return delay(3.0); + }).then(function() { + expect(video.paused).toBe(true); + expect(video.currentTime).toBe(timestamp); + done(); + }).catch(function(error) { + fail(error); + done(); + }); + }); + + it('does not rewind while paused', function(done) { + var timestamp; + player.setPlaybackStartTime(45); + player.load(newSource(plainManifest)).then(function() { + video.play(); + return waitForTargetTime(video, eventManager, 49, 6); + }).then(function() { + video.pause(); + timestamp = video.currentTime; + return delay(3.0); + }).then(function() { + player.setPlaybackRate(-1.0); + return delay(2.0); + }).then(function() { + expect(video.paused).toBe(true); + expect(video.currentTime).toBe(timestamp); + done(); + }).catch(function(error) { + fail(error); + done(); + }); + }); + + it('rewinds after pausing', function(done) { + var timestamp; + player.setPlaybackStartTime(45); + player.load(newSource(plainManifest)).then(function() { + video.play(); + return waitForMovement(video, eventManager); + }).then(function() { + player.setPlaybackRate(-1.0); + return delay(2.0); + }).then(function() { + video.pause(); + timestamp = video.currentTime; + return delay(3.0); + }).then(function() { + video.play(); + return delay(2.0); + }).then(function() { + expect(video.paused).toBe(false); + expect(video.currentTime).toBeLessThan(timestamp); + done(); + }).catch(function(error) { + fail(error); + done(); + }); + }); }); describe('getStats', function() {