af938e83 by David LaPalomento

Resolve relative URIs in playlists

Test for relative URIs when reading segment manifests and resolve them against the location of the manifest itself. Update test harness to support using different test manifests as XHR responses.
1 parent 26096d0d
......@@ -52,8 +52,13 @@ videojs.plugin('hls', function(options) {
fillBuffer = function() {
var
xhr = new window.XMLHttpRequest(),
segment = player.hls.currentPlaylist.segments[player.hls.currentMediaIndex];
xhr.open('GET', segment.uri);
segment = player.hls.currentPlaylist.segments[player.hls.currentMediaIndex],
segmentUri = segment.uri;
if (!(/^([A-z]*:)?\/\//).test(segmentUri)) {
// the segment URI is relative to the manifest
segmentUri = url.split('/').slice(0, -1).concat(segmentUri).join('/');
}
xhr.open('GET', segmentUri);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
......
......@@ -35,8 +35,15 @@ module('HLS', {
xhrParams = arguments;
};
this.send = function() {
// if the request URL looks like one of the test manifests, grab the
// contents off the global object
var manifestName = (/.*\/(.*)\.m3u8/).exec(xhrParams[1]);
if (manifestName) {
manifestName = manifestName[1];
}
this.responseText = window.manifests[manifestName || xhrParams[1]];
this.readyState = 4;
this.responseText = window.manifests['media'];
this.onreadystatechange();
};
};
......@@ -73,7 +80,7 @@ test('loads the specified manifest URL on init', function() {
ok(player.hls.manifest.segments, 'the segment entries are parsed');
strictEqual(player.hls.manifest,
player.hls.currentPlaylist,
'a playlist is selected');
'the playlist is selected');
strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA');
});
......@@ -83,7 +90,18 @@ test('starts downloading a segment on loadedmetadata', function() {
type: 'sourceopen'
});
strictEqual(xhrParams[1], '00001.ts', 'the first segment is requested');
strictEqual(xhrParams[1], 'manifest/00001.ts', 'the first segment is requested');
});
test('recognizes absolute URIs and uses them umnodified', function() {
player.hls('manifest/absoluteUris.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
strictEqual(xhrParams[1],
'http://example.com/00001.ts',
'the first segment is requested');
});
module('segment controller', {
......