7a9c64e1 by David LaPalomento

Merge pull request #38 from videojs/basic-live

Flash Tech Fix for Live UI
2 parents 3e56b573 0997e337
.DS_Store
dist/*
/node_modules/
*~
*.iml
......
......@@ -204,13 +204,8 @@ var
totalDuration = function(playlist) {
var
duration = 0,
i,
segment;
if (!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) {
......@@ -292,7 +287,8 @@ var
segmentXhr,
loadedPlaylist,
fillBuffer,
updateCurrentPlaylist;
updateCurrentPlaylist,
updateDuration;
// if the video element supports HLS natively, do nothing
if (videojs.hls.supportsNativeHls) {
......@@ -381,6 +377,22 @@ 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
tech = player.el().querySelector('.vjs-tech');
if(tech.vjs_setProperty) {
tech.vjs_setProperty('duration', player.duration());
}
// manually fire the duration change
player.trigger('durationchange');
};
/**
* Determine whether the current media playlist should be changed
* and trigger a switch if necessary. If a sufficiently fresh
* version of the target playlist is available, the switch will take
......@@ -406,8 +418,7 @@ var
playlist);
player.hls.media = playlist;
// update the duration
player.duration(totalDuration(player.hls.media));
updateDuration(player.hls.media);
}
};
......@@ -558,7 +569,7 @@ var
player.hls.media = player.hls.master.playlists[0];
// update the duration
player.duration(totalDuration(parser.manifest));
updateDuration(parser.manifest);
// periodicaly check if the buffer needs to be refilled
player.on('timeupdate', fillBuffer);
......@@ -585,7 +596,7 @@ var
var
buffered = player.buffered(),
bufferedTime = 0,
segment = player.hls.media.segments[player.hls.mediaIndex],
segment,
segmentUri,
startTime;
......@@ -594,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);
......