0997e337 by Tom Johnson

merge fix, add test

2 parents 6f5f4a98 906310ec
......@@ -204,14 +204,8 @@ var
totalDuration = function(playlist) {
var
duration = 0,
i,
segment;
if (!playlist || !playlist.segments) {
return 0;
}
i = playlist.segments.length;
segment,
i = (playlist.segments || []).length;
// if present, use the duration specified in the playlist
if (playlist.totalDuration) {
......@@ -386,10 +380,11 @@ var
* Update the player duration
*/
updateDuration = function(playlist) {
var tech;
// update the duration
player.duration(totalDuration(playlist));
// tell the flash tech of the new duration
var tech = player.el().querySelector('.vjs-tech');
tech = player.el().querySelector('.vjs-tech');
if(tech.vjs_setProperty) {
tech.vjs_setProperty('duration', player.duration());
}
......@@ -601,7 +596,7 @@ var
var
buffered = player.buffered(),
bufferedTime = 0,
segment = player.hls.media.segments[player.hls.mediaIndex],
segment,
segmentUri,
startTime;
......@@ -610,7 +605,13 @@ var
return;
}
// if no segments are available, do nothing
if (!player.hls.media.segments) {
return;
}
// if the video has finished downloading, stop trying to buffer
segment = player.hls.media.segments[player.hls.mediaIndex];
if (!segment) {
return;
}
......
......@@ -1109,4 +1109,28 @@ test('only reloads the active media playlist', function() {
'refreshed the active playlist');
});
test('does not break if the playlist has no segments', function() {
window.XMLHttpRequest = function () {
this.open = function () {};
this.send = function () {
this.readyState = 4;
this.status = 200;
this.responseText = '#EXTM3U\n' +
'#EXT-X-PLAYLIST-TYPE:VOD\n' +
'#EXT-X-TARGETDURATION:10\n';
this.onreadystatechange();
};
};
player.hls('manifest/master.m3u8');
try {
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
} catch(e) {
ok(false, 'an error was thrown');
throw e;
}
ok(true, 'no error was thrown');
});
})(window, window.videojs);
......