513236f5 by David LaPalomento

Let techOrder determine the mode to use

When a browser could support HTML or Flash based playback modes, allow video.js's techOrder to have precedence. It's very handy to be able to override the mode selection for debugging purposes, for instance.
1 parent ec888fb2
...@@ -25,7 +25,7 @@ keyFailed = function(key) { ...@@ -25,7 +25,7 @@ keyFailed = function(key) {
25 }; 25 };
26 26
27 videojs.Hls = videojs.extends(Component, { 27 videojs.Hls = videojs.extends(Component, {
28 constructor: function(tech, source) { 28 constructor: function(tech, options) {
29 var self = this, _player; 29 var self = this, _player;
30 30
31 Component.call(this, tech); 31 Component.call(this, tech);
...@@ -44,7 +44,8 @@ videojs.Hls = videojs.extends(Component, { ...@@ -44,7 +44,8 @@ videojs.Hls = videojs.extends(Component, {
44 } 44 }
45 } 45 }
46 this.tech_ = tech; 46 this.tech_ = tech;
47 this.source_ = source; 47 this.source_ = options.source;
48 this.mode_ = options.mode;
48 this.bytesReceived = 0; 49 this.bytesReceived = 0;
49 50
50 // loadingState_ tracks how far along the buffering process we 51 // loadingState_ tracks how far along the buffering process we
...@@ -87,7 +88,8 @@ videojs.Hls.canPlaySource = function() { ...@@ -87,7 +88,8 @@ videojs.Hls.canPlaySource = function() {
87 * the browser it is running in. It is not necessary to use or modify 88 * the browser it is running in. It is not necessary to use or modify
88 * this object in normal usage. 89 * this object in normal usage.
89 */ 90 */
90 videojs.HlsSourceHandler = { 91 videojs.HlsSourceHandler = function(mode) {
92 return {
91 canHandleSource: function(srcObj) { 93 canHandleSource: function(srcObj) {
92 var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i; 94 var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
93 95
...@@ -98,17 +100,21 @@ videojs.HlsSourceHandler = { ...@@ -98,17 +100,21 @@ videojs.HlsSourceHandler = {
98 return mpegurlRE.test(srcObj.type); 100 return mpegurlRE.test(srcObj.type);
99 }, 101 },
100 handleSource: function(source, tech) { 102 handleSource: function(source, tech) {
101 tech.hls = new videojs.Hls(tech, source); 103 tech.hls = new videojs.Hls(tech, {
104 source: source,
105 mode: mode
106 });
102 tech.hls.src(source.src); 107 tech.hls.src(source.src);
103 return tech.hls; 108 return tech.hls;
104 } 109 }
110 };
105 }; 111 };
106 // register with the appropriate tech 112
113 // register source handlers with the appropriate techs
107 if (videojs.MediaSource.supportsNativeMediaSources()) { 114 if (videojs.MediaSource.supportsNativeMediaSources()) {
108 videojs.getComponent('Html5').registerSourceHandler(videojs.HlsSourceHandler); 115 videojs.getComponent('Html5').registerSourceHandler(videojs.HlsSourceHandler('html5'));
109 } else {
110 videojs.getComponent('Flash').registerSourceHandler(videojs.HlsSourceHandler);
111 } 116 }
117 videojs.getComponent('Flash').registerSourceHandler(videojs.HlsSourceHandler('flash'));
112 118
113 // the desired length of video to maintain in the buffer, in seconds 119 // the desired length of video to maintain in the buffer, in seconds
114 videojs.Hls.GOAL_BUFFER_LENGTH = 30; 120 videojs.Hls.GOAL_BUFFER_LENGTH = 30;
...@@ -121,7 +127,7 @@ videojs.Hls.prototype.src = function(src) { ...@@ -121,7 +127,7 @@ videojs.Hls.prototype.src = function(src) {
121 return; 127 return;
122 } 128 }
123 129
124 this.mediaSource = new videojs.MediaSource(); 130 this.mediaSource = new videojs.MediaSource({ mode: this.mode_ });
125 this.segmentBuffer_ = []; 131 this.segmentBuffer_ = [];
126 132
127 // if the stream contains ID3 metadata, expose that as a metadata 133 // if the stream contains ID3 metadata, expose that as a metadata
......
...@@ -2510,19 +2510,21 @@ test('aborts the source buffer on disposal', function() { ...@@ -2510,19 +2510,21 @@ test('aborts the source buffer on disposal', function() {
2510 }); 2510 });
2511 2511
2512 test('the source handler supports HLS mime types', function() { 2512 test('the source handler supports HLS mime types', function() {
2513 ok(videojs.HlsSourceHandler.canHandleSource({ 2513 ['html5', 'flash'].forEach(function(techName) {
2514 ok(videojs.HlsSourceHandler(techName).canHandleSource({
2514 type: 'aPplicatiOn/x-MPegUrl' 2515 type: 'aPplicatiOn/x-MPegUrl'
2515 }), 'supports x-mpegurl'); 2516 }), 'supports x-mpegurl');
2516 ok(videojs.HlsSourceHandler.canHandleSource({ 2517 ok(videojs.HlsSourceHandler(techName).canHandleSource({
2517 type: 'aPplicatiOn/VnD.aPPle.MpEgUrL' 2518 type: 'aPplicatiOn/VnD.aPPle.MpEgUrL'
2518 }), 'supports vnd.apple.mpegurl'); 2519 }), 'supports vnd.apple.mpegurl');
2519 2520
2520 ok(!(videojs.HlsSourceHandler.canHandleSource({ 2521 ok(!(videojs.HlsSourceHandler(techName).canHandleSource({
2521 type: 'video/mp4' 2522 type: 'video/mp4'
2522 }) instanceof videojs.Hls), 'does not support mp4'); 2523 }) instanceof videojs.Hls), 'does not support mp4');
2523 ok(!(videojs.HlsSourceHandler.canHandleSource({ 2524 ok(!(videojs.HlsSourceHandler(techName).canHandleSource({
2524 type: 'video/x-flv' 2525 type: 'video/x-flv'
2525 }) instanceof videojs.Hls), 'does not support flv'); 2526 }) instanceof videojs.Hls), 'does not support flv');
2527 });
2526 }); 2528 });
2527 2529
2528 test('has no effect if native HLS is available', function() { 2530 test('has no effect if native HLS is available', function() {
......