Skip to content

Commit

Permalink
Re-allow pausing while rewinding.
Browse files Browse the repository at this point in the history
This fixes a regression and adds more integration tests.

Closes #130

Change-Id: Idd386931ae6d9f37052f24438ebcba10774e3451
  • Loading branch information
Timothy Drews committed Sep 11, 2015
1 parent 35d4c5e commit 6049d67
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ shaka.player.Player.prototype.onPause_ = function(event) {
if (!isNaN(elapsed)) {
this.stats_.logPlayTime(elapsed);
}
this.cancelRewindTimer_();
};


Expand Down Expand Up @@ -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) {
Expand Down
72 changes: 72 additions & 0 deletions spec/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 6049d67

Please sign in to comment.