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.
Showing
2 changed files
with
42 additions
and
34 deletions
... | @@ -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,28 +88,33 @@ videojs.Hls.canPlaySource = function() { | ... | @@ -87,28 +88,33 @@ 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) { |
91 | canHandleSource: function(srcObj) { | 92 | return { |
92 | var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i; | 93 | canHandleSource: function(srcObj) { |
93 | 94 | var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i; | |
94 | // favor native HLS support if it's available | 95 | |
95 | if (videojs.Hls.supportsNativeHls) { | 96 | // favor native HLS support if it's available |
96 | return false; | 97 | if (videojs.Hls.supportsNativeHls) { |
98 | return false; | ||
99 | } | ||
100 | return mpegurlRE.test(srcObj.type); | ||
101 | }, | ||
102 | handleSource: function(source, tech) { | ||
103 | tech.hls = new videojs.Hls(tech, { | ||
104 | source: source, | ||
105 | mode: mode | ||
106 | }); | ||
107 | tech.hls.src(source.src); | ||
108 | return tech.hls; | ||
97 | } | 109 | } |
98 | return mpegurlRE.test(srcObj.type); | 110 | }; |
99 | }, | ||
100 | handleSource: function(source, tech) { | ||
101 | tech.hls = new videojs.Hls(tech, source); | ||
102 | tech.hls.src(source.src); | ||
103 | return tech.hls; | ||
104 | } | ||
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 | type: 'aPplicatiOn/x-MPegUrl' | 2514 | ok(videojs.HlsSourceHandler(techName).canHandleSource({ |
2515 | }), 'supports x-mpegurl'); | 2515 | type: 'aPplicatiOn/x-MPegUrl' |
2516 | ok(videojs.HlsSourceHandler.canHandleSource({ | 2516 | }), 'supports x-mpegurl'); |
2517 | type: 'aPplicatiOn/VnD.aPPle.MpEgUrL' | 2517 | ok(videojs.HlsSourceHandler(techName).canHandleSource({ |
2518 | }), 'supports vnd.apple.mpegurl'); | 2518 | type: 'aPplicatiOn/VnD.aPPle.MpEgUrL' |
2519 | 2519 | }), 'supports vnd.apple.mpegurl'); | |
2520 | ok(!(videojs.HlsSourceHandler.canHandleSource({ | 2520 | |
2521 | type: 'video/mp4' | 2521 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ |
2522 | }) instanceof videojs.Hls), 'does not support mp4'); | 2522 | type: 'video/mp4' |
2523 | ok(!(videojs.HlsSourceHandler.canHandleSource({ | 2523 | }) instanceof videojs.Hls), 'does not support mp4'); |
2524 | type: 'video/x-flv' | 2524 | ok(!(videojs.HlsSourceHandler(techName).canHandleSource({ |
2525 | }) instanceof videojs.Hls), 'does not support flv'); | 2525 | type: 'video/x-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() { | ... | ... |
-
Please register or sign in to post a comment