Skip to content

Commit

Permalink
Update fast-forward and rewind to work with play/pause.
Browse files Browse the repository at this point in the history
Closes #130.

Change-Id: I33ed2e2ac0014eb3b271f72904996d669b0f13ee
  • Loading branch information
natalieharris authored and Timothy Drews committed Jul 30, 2015
1 parent 1688386 commit 8c62506
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ playerControls.init = function(video) {
// play
playButton.addEventListener('click', function() {
if (!video.src) return;
playerControls.player_.setPlaybackRate(1);
video.play();
});
video.addEventListener('play', function() {
Expand Down Expand Up @@ -247,6 +248,7 @@ playerControls.onRewind = function() {
var rate = playerControls.player_.getPlaybackRate();
playerControls.player_.setPlaybackRate(
rate > 0 || rate < -4 ? -1.0 : rate * 2);
playerControls.video_.play();
};


Expand All @@ -258,6 +260,7 @@ playerControls.onFastForward = function() {
if (!playerControls.player_) return;
var rate = playerControls.player_.getPlaybackRate();
playerControls.player_.setPlaybackRate(rate < 0 || rate > 4 ? 1.0 : rate * 2);
playerControls.video_.play();
};


Expand Down
30 changes: 24 additions & 6 deletions lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ shaka.player.Player.prototype.onPause_ = function(event) {
if (!isNaN(elapsed)) {
this.stats_.logPlayTime(elapsed);
}
this.cancelRewindTimer_();
};


Expand Down Expand Up @@ -872,12 +873,20 @@ shaka.player.Player.prototype.cancelWatchdogTimer_ = function() {
shaka.player.Player.prototype.onRewindTimer_ =
function(startVideoTime, startWallTime, rate) {
shaka.asserts.assert(rate < 0);
var offset = ((Date.now() - startWallTime) / 1000) * rate;
this.video_.currentTime = startVideoTime + offset;

var callback = this.onRewindTimer_.bind(
this, startVideoTime, startWallTime, rate);
this.rewindTimer_ = window.setTimeout(callback, 100);
var rewindOffset =
shaka.player.Player.REWIND_UPDATE_INTERVAL_ * Math.abs(rate);
if (this.video_.buffered.length &&
this.video_.buffered.start(0) + rewindOffset < this.video_.currentTime) {
var offset = ((Date.now() - startWallTime) / 1000) * rate;
this.video_.currentTime = startVideoTime + offset;

var callback = this.onRewindTimer_.bind(
this, startVideoTime, startWallTime, rate);
this.rewindTimer_ = window.setTimeout(
callback, shaka.player.Player.REWIND_UPDATE_INTERVAL_ * 1000);
} else {
this.video_.pause();
}
};


Expand Down Expand Up @@ -968,6 +977,15 @@ shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.1;
shaka.player.Player.BUFFERED_FUDGE_FACTOR_ = 0.05;


/**
* The number of seconds for each rewind update interval.
*
* @private {number}
* @const
*/
shaka.player.Player.REWIND_UPDATE_INTERVAL_ = 0.1;


/**
* A map of MediaError codes to error messages. The JS interpreter won't take
* a symbolic name as a key, so the symbolic names for these error codes appear
Expand Down

0 comments on commit 8c62506

Please sign in to comment.