6b05241f by David LaPalomento

Fix seek issue when first playing live streams

When you first called play() on a live stream, the seek wouldn't complete because of a condition in fillBuffer() that prevented buffering until the player had started. Allow fillBuffer() to begin buffering in a live stream at a specified position, which ensures drainBuffer() will clean up the seek correctly.
1 parent 72f9507d
......@@ -317,7 +317,6 @@ videojs.Hls.prototype.setupMetadataCueTranslation_ = function() {
* ended.
*/
videojs.Hls.prototype.play = function() {
var media;
if (this.ended()) {
this.mediaIndex = 0;
}
......@@ -327,9 +326,7 @@ videojs.Hls.prototype.play = function() {
if (this.duration() === Infinity &&
this.playlists.media() &&
!this.player().hasClass('vjs-has-started')) {
media = this.playlists.media();
this.mediaIndex = videojs.Hls.getMediaIndexForLive_(media);
this.setCurrentTime(videojs.Hls.Playlist.seekable(media).end(0));
this.setCurrentTime(this.seekable().end(0));
}
// delegate back to the Flash implementation
......@@ -645,7 +642,8 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
// being buffering so we don't preload data that will never be
// played
if (!this.playlists.media().endList &&
!this.player().hasClass('vjs-has-started')) {
!this.player().hasClass('vjs-has-started') &&
offset === undefined) {
return;
}
......
......@@ -1663,19 +1663,33 @@ test('updates the media index when a playlist reloads', function() {
test('live playlist starts three target durations before live', function() {
var mediaPlaylist;
player.src({
src: 'http://example.com/manifest/liveStart30sBefore.m3u8',
src: 'live.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
standardXHRResponse(requests.shift());
requests.shift().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-MEDIA-SEQUENCE:101\n' +
'#EXTINF:10,\n' +
'0.ts\n' +
'#EXTINF:10,\n' +
'1.ts\n' +
'#EXTINF:10,\n' +
'2.ts\n' +
'#EXTINF:10,\n' +
'3.ts\n' +
'#EXTINF:10,\n' +
'4.ts\n');
equal(player.hls.mediaIndex, 0, 'waits for the first play to start buffering');
equal(requests.length, 0, 'no outstanding segment request');
player.play();
mediaPlaylist = player.hls.playlists.media();
equal(player.hls.mediaIndex, 6, 'mediaIndex is updated at play');
equal(player.currentTime(), videojs.Hls.Playlist.seekable(mediaPlaylist).end(0));
equal(player.hls.mediaIndex, 1, 'mediaIndex is updated at play');
equal(player.currentTime(), player.seekable().end(0));
equal(requests.length, 1, 'begins buffering');
});
test('does not reset live currentTime if mediaIndex is one beyond the last available segment', function() {
......