Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add player method to set playback start time ahead of downloading chunks #123

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/player/http_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ shaka.player.HttpVideoSource = function(mediaUrl, textUrl, drmScheme) {

/** @private {HTMLTrackElement} */
this.textTrack_ = null;

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

Expand Down Expand Up @@ -167,6 +170,13 @@ shaka.player.HttpVideoSource.prototype.enableTextTrack = function(enabled) {
};


/** @override */
shaka.player.HttpVideoSource.prototype.setPlaybackStartTime =
function(startTime) {
this.playbackStartTime_ = startTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this should be a no-op for HttpVideoSource, or this value should be used to set video.currentTime in attach().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've changed to a no-op.

};


/** @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 time in seconds from which point video playback should begin.
*
* @param {?number} startTime
*/
shaka.player.IVideoSource.prototype.setPlaybackStartTime =
function(startTime) {};
24 changes: 24 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,25 @@ shaka.player.Player.prototype.getRestrictions = function() {
};


/**
* @param {number} startTime The time (in seconds) you want to
* set as the starting time for playback.
* @export
*/
shaka.player.Player.prototype.setPlaybackStartTime = function(startTime) {
this.playbackStartTime_ = startTime;
};


/**
* @return {?number} The currently set start time
* @export
*/
shaka.player.Player.prototype.getPlaybackStartTime = function() {
return this.playbackStartTime_;
};


/**
* @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;
}
};