348ef762 by Gary Katsevman

Merge branch 'master' into withcredentials

2 parents e25f8997 7a9c64e1
.DS_Store
dist/*
/node_modules/
*~
*.iml
......
......@@ -7,7 +7,10 @@ notifications:
hipchat:
rooms:
secure: l5TTd5JuPAW883PtcyaIBcJI9Chr9JpsZPQAEUBKAgIEwzuS6y7t5arlkS1PwH6gi1FADzYDf+OXSIou4GkTSrIetnBcT/SAgF0gBKgIhj+eRkuCfZ4VaC7BPhfZ0hgYRE+5Ejf5BM2MJafRm0pj7OlqG4xKrQZwtuV1te5r3JY=
irc: chat.freenode.net#videojs
irc:
channels:
- "chat.freenode.net#videojs"
use_notice: true
#addons:
#sauce_connect:
#username:
......
......@@ -223,13 +223,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) {
......@@ -311,7 +306,8 @@ var
segmentXhr,
loadedPlaylist,
fillBuffer,
updateCurrentPlaylist;
updateCurrentPlaylist,
updateDuration;
// if the video element supports HLS natively, do nothing
if (videojs.hls.supportsNativeHls) {
......@@ -402,6 +398,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
......@@ -427,8 +439,7 @@ var
playlist);
player.hls.media = playlist;
// update the duration
player.duration(totalDuration(player.hls.media));
updateDuration(player.hls.media);
}
};
......@@ -579,7 +590,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);
......@@ -606,7 +617,7 @@ var
var
buffered = player.buffered(),
bufferedTime = 0,
segment = player.hls.media.segments[player.hls.mediaIndex],
segment,
segmentUri,
startTime;
......@@ -615,7 +626,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;
}
......
......@@ -1171,4 +1171,28 @@ test('if withCredentials option is used, withCredentials is set on the XHR objec
ok(requests[0].withCredentials, "with credentials should be set to true if that option is passed in");
});
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);
......