|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | // TODO: 1) Limit the number of the buffers we hold in memory if MSE is slow to consume them
|
18 |
| - // 2) Stop downloading segments when we've got a sensible numbers buffered |
19 |
| - // 3) Support scrubbing |
| 18 | + // 2) Stop downloading segments when we've got a sensible number buffered (Or even better a configurable duration...) |
| 19 | + // 3) Support scrubbing to un-buffered points in the content |
20 | 20 |
|
21 | 21 | // Track prototype
|
22 | 22 | function Track(mediaSource, codecString, segments) {
|
|
73 | 73 | var mediaSource = new MediaSource();
|
74 | 74 | var player = document.querySelector('#player');
|
75 | 75 |
|
76 |
| - // TODO: This is a bad implementation of a SASH manifest reader. Clean it up & modularise. |
77 |
| - // TODO: Since this will become a module, also using jquery is a little lazy |
78 |
| - $.getJSON( "manifest.json", function( manifest ) { |
79 |
| - for (i = 0; i < manifest.adaptation_sets.length; i++) { |
80 |
| - for (j = 0; j < Object.keys(manifest.adaptation_sets[i].representations).length; j++) { |
81 |
| - repid = Object.keys(manifest.adaptation_sets[i].representations)[j]; |
82 |
| - var codecString = manifest.adaptation_sets[i].mime_type + '; codecs="' + manifest.adaptation_sets[i].representations[repid].codecs + '"'; |
83 |
| - var segments = [manifest.adaptation_sets[i].segment_template.init.replace('$representation$', repid)]; |
84 |
| - for (k = manifest.adaptation_sets[i].segment_template.start_number; k <= manifest.adaptation_sets[i].segment_template.end_number; k++) { |
85 |
| - segments.push(manifest.adaptation_sets[i].segment_template.media.replace('$representation$', repid).replace('$number$', k)); |
86 |
| - } |
87 |
| - new Track(mediaSource, codecString, segments); |
| 76 | + $.getJSON( "0.2.json", function( manifest ) { |
| 77 | + |
| 78 | + // Grab the first Audio and Video renditions we find, and push them onto MSE |
| 79 | + ['video', 'audio'].forEach(function(element) { |
| 80 | + firstRenditionName = Object.keys(manifest[element][0].renditions)[0]; |
| 81 | + firstRendition = manifest[element][0].renditions[firstRenditionName]; |
| 82 | + var codecString = manifest[element][0].mime_type + '; codecs="' + firstRendition.codecs + '"'; |
| 83 | + var segments = [manifest[element][0].segment_template.init.replace('$rendition$', firstRenditionName)]; |
| 84 | + for (k = manifest[element][0].segment_template.start_number; k <= manifest[element][0].segment_template.end_number; k++) { |
| 85 | + segments.push(manifest[element][0].segment_template.media.replace('$rendition$', firstRenditionName).replace('$number$', k)); |
88 | 86 | }
|
89 |
| - } |
| 87 | + new Track(mediaSource, codecString, segments); |
| 88 | + }); |
90 | 89 |
|
91 | 90 | // Only init MSE once the manifest is loaded.
|
92 | 91 | player.src = window.URL.createObjectURL(mediaSource);
|
|
0 commit comments