66510e67 by David LaPalomento

Merge branch 'stevemayhew-fix-keyurl'

2 parents 7436e467 731fd8d6
......@@ -472,13 +472,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
}
// resolve the segment URL relative to the playlist
segmentUri = this.playlistUriToUrl(segment.uri);
this.loadSegment(segmentUri, offset);
};
videojs.Hls.prototype.playlistUriToUrl = function(segmentRelativeUrl) {
var playListUrl;
// resolve the segment URL relative to the playlist
if (this.playlists.media().uri === this.src_) {
segmentUri = resolveUrl(this.src_, segment.uri);
playListUrl = resolveUrl(this.src_, segmentRelativeUrl);
} else {
segmentUri = resolveUrl(resolveUrl(this.src_, this.playlists.media().uri || ''), segment.uri);
playListUrl = resolveUrl(resolveUrl(this.src_, this.playlists.media().uri || ''), segmentRelativeUrl);
}
this.loadSegment(segmentUri, offset);
return playListUrl;
};
/*
......@@ -684,7 +691,7 @@ videojs.Hls.prototype.fetchKeys = function(playlist, index) {
key = playlist.segments[i].key;
if (key && !key.bytes && !keyFailed(key)) {
keyXhr = videojs.Hls.xhr({
url: resolveUrl(playlist.uri, key.uri),
url: this.playlistUriToUrl(key.uri),
responseType: 'arraybuffer',
withCredentials: settings.withCredentials
}, function(err, url) {
......
......@@ -1612,6 +1612,48 @@ test('calling fetchKeys() when a new playlist is loaded will create an XHR', fun
player.hls.playlists.media = oldMedia;
});
test('fetchKeys() resolves URLs relative to the master playlist', function() {
player.src({
src: 'video/master-encrypted.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
requests.shift().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=17\n' +
'playlist/playlist.m3u8\n' +
'#EXT-X-ENDLIST\n');
requests.shift().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-TARGETDURATION:15\n' +
'#EXT-X-KEY:METHOD=AES-128,URI="keys/key.php"\n' +
'#EXTINF:2.833,\n' +
'http://media.example.com/fileSequence1.ts\n' +
'#EXT-X-ENDLIST\n');
equal(requests.length, 2, 'requested two URLs');
ok((/video\/playlist\/keys\/key\.php$/).test(requests[0].url),
'resolves multiple relative paths');
});
test('fetchKeys() resolves URLs relative to their containing playlist', function() {
player.src({
src: 'video/media-encrypted.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
requests.shift().respond(200, null,
'#EXTM3U\n' +
'#EXT-X-TARGETDURATION:15\n' +
'#EXT-X-KEY:METHOD=AES-128,URI="keys/key.php"\n' +
'#EXTINF:2.833,\n' +
'http://media.example.com/fileSequence1.ts\n' +
'#EXT-X-ENDLIST\n');
equal(requests.length, 2, 'requested two URLs');
ok((/video\/keys\/key\.php$/).test(requests[0].url),
'resolves multiple relative paths');
});
test('a new keys XHR is created when a previous key XHR finishes', function() {
player.src({
src: 'https://example.com/encrypted-media.m3u8',
......