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) { ...@@ -52,8 +52,13 @@ videojs.plugin('hls', function(options) {
52 fillBuffer = function() { 52 fillBuffer = function() {
53 var 53 var
54 xhr = new window.XMLHttpRequest(), 54 xhr = new window.XMLHttpRequest(),
55 segment = player.hls.currentPlaylist.segments[player.hls.currentMediaIndex]; 55 segment = player.hls.currentPlaylist.segments[player.hls.currentMediaIndex],
56 xhr.open('GET', segment.uri); 56 segmentUri = segment.uri;
57 if (!(/^([A-z]*:)?\/\//).test(segmentUri)) {
58 // the segment URI is relative to the manifest
59 segmentUri = url.split('/').slice(0, -1).concat(segmentUri).join('/');
60 }
61 xhr.open('GET', segmentUri);
57 xhr.responseType = 'arraybuffer'; 62 xhr.responseType = 'arraybuffer';
58 xhr.onreadystatechange = function() { 63 xhr.onreadystatechange = function() {
59 if (xhr.readyState === 4) { 64 if (xhr.readyState === 4) {
......
...@@ -35,8 +35,15 @@ module('HLS', { ...@@ -35,8 +35,15 @@ module('HLS', {
35 xhrParams = arguments; 35 xhrParams = arguments;
36 }; 36 };
37 this.send = function() { 37 this.send = function() {
38 // if the request URL looks like one of the test manifests, grab the
39 // contents off the global object
40 var manifestName = (/.*\/(.*)\.m3u8/).exec(xhrParams[1]);
41 if (manifestName) {
42 manifestName = manifestName[1];
43 }
44 this.responseText = window.manifests[manifestName || xhrParams[1]];
45
38 this.readyState = 4; 46 this.readyState = 4;
39 this.responseText = window.manifests['media'];
40 this.onreadystatechange(); 47 this.onreadystatechange();
41 }; 48 };
42 }; 49 };
...@@ -73,7 +80,7 @@ test('loads the specified manifest URL on init', function() { ...@@ -73,7 +80,7 @@ test('loads the specified manifest URL on init', function() {
73 ok(player.hls.manifest.segments, 'the segment entries are parsed'); 80 ok(player.hls.manifest.segments, 'the segment entries are parsed');
74 strictEqual(player.hls.manifest, 81 strictEqual(player.hls.manifest,
75 player.hls.currentPlaylist, 82 player.hls.currentPlaylist,
76 'a playlist is selected'); 83 'the playlist is selected');
77 strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA'); 84 strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA');
78 }); 85 });
79 86
...@@ -83,7 +90,18 @@ test('starts downloading a segment on loadedmetadata', function() { ...@@ -83,7 +90,18 @@ test('starts downloading a segment on loadedmetadata', function() {
83 type: 'sourceopen' 90 type: 'sourceopen'
84 }); 91 });
85 92
86 strictEqual(xhrParams[1], '00001.ts', 'the first segment is requested'); 93 strictEqual(xhrParams[1], 'manifest/00001.ts', 'the first segment is requested');
94 });
95
96 test('recognizes absolute URIs and uses them umnodified', function() {
97 player.hls('manifest/absoluteUris.m3u8');
98 videojs.mediaSources[player.currentSrc()].trigger({
99 type: 'sourceopen'
100 });
101
102 strictEqual(xhrParams[1],
103 'http://example.com/00001.ts',
104 'the first segment is requested');
87 }); 105 });
88 106
89 module('segment controller', { 107 module('segment controller', {
......