Skip to content

Commit

Permalink
Do not assign currentTime of video unless MetaData is available.
Browse files Browse the repository at this point in the history
Fixes shaka-project#101
Required for Firefox's and IE's MediaElement implementations.
  • Loading branch information
Nick Desaulniers committed Jun 18, 2015
1 parent 96b369e commit 67780cf
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/player/stream_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,13 @@ shaka.player.StreamVideoSource.prototype.startStreams_ = function(
// Set the video's current time before starting the streams so that the
// streams begin buffering at the stream start time.
shaka.log.info('Starting each stream from', streamStartTime);
this.video.currentTime = streamStartTime;

if (this.video.readyState >= HTMLMediaElement.HAVE_METADATA) {
this.video.currentTime = streamStartTime;
} else {
this.video.addEventListener('loadedmetadata',
this.setInitialCurrentTime.bind(this, streamStartTime));
}

// Start the streams.
for (var type in this.streamsByType_) {
Expand All @@ -1135,6 +1141,18 @@ shaka.player.StreamVideoSource.prototype.startStreams_ = function(
this.enableTextTrack(this.subsNeeded_);
};

/**
* Sets the currentTime of the video element. This is deferred if metadata
* has not been loaded yet.
*
* @param {number} streamStartTime
* @private
*/
shaka.player.StreamVideoSource.prototype.setInitialCurrentTime = function(
streamStartTime) {
this.video.currentTime = streamStartTime;
this.video.removeEventListener('loadedmetadata', this.setInitialCurrentTime);
};

/**
* Start streams hook. Called immediately before setting the video's duration
Expand Down

0 comments on commit 67780cf

Please sign in to comment.