9e12846d by David LaPalomento

Wait until the player is ready to set the source. Capture the target time during seeks.

Opening the media source before the player is fully initialized would result in loadstart happening too early and the big play button getting stuck over the player. The video element should report the desired currentTime while a seek is pending, so store this value when currentTime is set and return it until a seek completes successfully.
1 parent dc2fa763
......@@ -183,21 +183,31 @@ var
initSource = function(player, mediaSource, srcUrl) {
var
segmentParser = new videojs.Hls.SegmentParser(),
settings = videojs.util.mergeOptions({}, player.options().hls),
lastSeekedTime,
segmentXhr,
settings = videojs.util.mergeOptions({}, player.options().hls),
fillBuffer,
updateDuration;
player.hls.currentTime = function(currentTime) {
if (currentTime === undefined) {
return this.el().vjs_getProperty('currentTime');
player.hls.currentTime = function() {
if (lastSeekedTime) {
return lastSeekedTime;
}
return this.el().vjs_getProperty('currentTime');
};
player.hls.setCurrentTime = function(currentTime) {
if (!(this.playlists && this.playlists.media())) {
// return immediately if the metadata is not ready yet
return 0;
}
// save the seek target so currentTime can report it correctly
// while the seek is pending
lastSeekedTime = currentTime;
// determine the requested segment
this.mediaIndex =
getMediaIndexByTime(this.playlists.media(), currentTime);
......@@ -330,8 +340,9 @@ var
bufferedTime = player.buffered().end(0) - player.currentTime();
}
// if there is plenty of content in the buffer, relax for awhile
if (bufferedTime >= goalBufferLength) {
// if there is plenty of content in the buffer and we're not
// seeking, relax for awhile
if (typeof offset !== 'number' && bufferedTime >= goalBufferLength) {
return;
}
......@@ -382,10 +393,15 @@ var
// if we're refilling the buffer after a seek, scan through the muxed
// FLV tags until we find the one that is closest to the desired
// playback time
if (offset !== undefined && typeof offset === "number") {
if (typeof offset === 'number') {
while (segmentParser.getTags()[0].pts < offset) {
segmentParser.getNextTag();
}
// tell the SWF where we will be seeking to
player.hls.el().vjs_setProperty('currentTime',
segmentParser.getTags()[0].pts * 0.001);
lastSeekedTime = null;
}
while (segmentParser.tagsAvailable()) {
......@@ -473,6 +489,7 @@ videojs.Hls = videojs.Flash.extend({
videojs.Hls.prototype.src = function(src) {
var
player = this.player(),
self = this,
mediaSource,
source;
......@@ -484,8 +501,8 @@ videojs.Hls.prototype.src = function(src) {
};
this.mediaSource = mediaSource;
initSource(player, mediaSource, src);
this.ready(function() {
this.el().vjs_src(source.src);
this.player().ready(function() {
self.el().vjs_src(source.src);
});
}
};
......
......@@ -49,6 +49,7 @@ var
tech = player.el().querySelector('.vjs-tech');
tech.vjs_getProperty = function() {};
tech.vjs_setProperty = function() {};
tech.vjs_src = function() {};
videojs.Flash.onReady(tech.id);
......@@ -654,6 +655,7 @@ test('does not download the next segment if the buffer is full', function() {
player.trigger('timeupdate');
console.log(requests);
strictEqual(requests.length, 1, 'no segment request was made');
});
......@@ -754,7 +756,7 @@ test('cancels outstanding XHRs when seeking', function() {
// trigger a segment download request
player.trigger('timeupdate');
// attempt to seek while the download is in progress
player.hls.currentTime(7);
player.currentTime(7);
ok(requests[1].aborted, 'XHR aborted');
strictEqual(requests.length, 3, 'opened new XHR');
......@@ -830,7 +832,7 @@ test('drops tags before the target timestamp when seeking', function() {
bytes: i
});
}
player.hls.currentTime(7);
player.currentTime(7);
standardXHRResponse(requests[2]);
while (callbacks.length) {
......@@ -876,7 +878,7 @@ test('clears pending buffer updates when seeking', function() {
// seek to 7s
tags.push({ pts: 7000, bytes: 7 });
player.hls.currentTime(7);
player.currentTime(7);
standardXHRResponse(requests[2]);
while (callbacks.length) {
......