Skip to content

Commit

Permalink
Merge pull request #123 from sanbornhnewyyz/feature/setPlaybackStartTime
Browse files Browse the repository at this point in the history
Add player method to set playback start time ahead of downloading chunks
  • Loading branch information
tdrews committed Jul 13, 2015
2 parents a04bea1 + 7148fa7 commit 03703f1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/player/http_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ shaka.player.HttpVideoSource.prototype.enableTextTrack = function(enabled) {
};


/** @override */
shaka.player.HttpVideoSource.prototype.setPlaybackStartTime =
function(startTime) {
// nop
};


/** @override */
shaka.player.HttpVideoSource.prototype.enableAdaptation = function(enabled) {
// nop
Expand Down
9 changes: 9 additions & 0 deletions lib/player/i_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,12 @@ shaka.player.IVideoSource.prototype.isOffline = function() {};
* @return {boolean} True if the stream is live.
*/
shaka.player.IVideoSource.prototype.isLive = function() {};


/**
* Sets the desired time (in seconds) to begin playback from.
*
* @param {?number} startTime
*/
shaka.player.IVideoSource.prototype.setPlaybackStartTime =
function(startTime) {};
15 changes: 15 additions & 0 deletions lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ shaka.player.Player = function(video) {

/** @private {!shaka.player.DrmSchemeInfo.Restrictions} */
this.restrictions_ = new shaka.player.DrmSchemeInfo.Restrictions();

/** @private {?number} */
this.playbackStartTime_ = null;
};
goog.inherits(shaka.player.Player, shaka.util.FakeEventTarget);

Expand Down Expand Up @@ -269,6 +272,8 @@ shaka.player.Player.prototype.load = function(videoSource) {
this.onFirstTimestamp_.bind(this));
}

videoSource.setPlaybackStartTime(this.playbackStartTime_);

// Sync adaptation setting, which could have been set before this source was
// loaded.
videoSource.enableAdaptation(this.adaptationEnabled_);
Expand Down Expand Up @@ -685,6 +690,16 @@ shaka.player.Player.prototype.getRestrictions = function() {
};


/**
* @param {number} startTime Desired time (in seconds) for playback
* to begin from.
* @export
*/
shaka.player.Player.prototype.setPlaybackStartTime = function(startTime) {
this.playbackStartTime_ = startTime;
};


/**
* @return {boolean}
* @export
Expand Down
21 changes: 19 additions & 2 deletions lib/player/stream_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ shaka.player.StreamVideoSource = function(manifestInfo, estimator, abrManager) {

/** @private {?number} */
this.seekRangeTimer_ = null;

/** @private {?number} */
this.playbackStartTime_ = null;
};
goog.inherits(shaka.player.StreamVideoSource, shaka.util.FakeEventTarget);

Expand Down Expand Up @@ -653,6 +656,13 @@ shaka.player.StreamVideoSource.prototype.enableTextTrack = function(enabled) {
};


/** @override */
shaka.player.StreamVideoSource.prototype.setPlaybackStartTime =
function(startTime) {
this.playbackStartTime_ = startTime;
};


/** @override */
shaka.player.StreamVideoSource.prototype.enableAdaptation = function(enabled) {
this.abrManager_.enable(enabled);
Expand Down Expand Up @@ -1113,7 +1123,15 @@ shaka.player.StreamVideoSource.prototype.startStreams_ = function(
streamStartTime = streamLimits.end;
} else {
this.mediaSource.duration = streamLimits.end - streamLimits.start;
streamStartTime = streamLimits.start;
// If a specific start time was set, and it's within the
// stream limits, use that as the start time.
if (this.playbackStartTime_ &&
this.playbackStartTime_ <= streamLimits.end &&
this.playbackStartTime_ >= streamLimits.start) {
streamStartTime = this.playbackStartTime_;
} else {
streamStartTime = streamLimits.start;
}
}

// Set the video's current time before starting the streams so that the
Expand Down Expand Up @@ -1656,4 +1674,3 @@ shaka.player.StreamVideoSource.prototype.cancelSeekRangeTimer_ = function() {
this.seekRangeTimer_ = null;
}
};

0 comments on commit 03703f1

Please sign in to comment.