Put HLS at the front of the techOrder by default. Make the tech a no-op if HLS i…
…s supported natively. Update the default techOrder to include HLS support first when the plugin is loaded. Prefer HTML5 implementations if they're available. Added tests to verify both constraints.
Showing
2 changed files
with
45 additions
and
3 deletions
... | @@ -595,6 +595,26 @@ videojs.Hls = videojs.Flash.extend({ | ... | @@ -595,6 +595,26 @@ videojs.Hls = videojs.Flash.extend({ |
595 | } | 595 | } |
596 | }); | 596 | }); |
597 | 597 | ||
598 | /** | ||
599 | * Whether the browser has built-in HLS support. | ||
600 | */ | ||
601 | videojs.Hls.supportsNativeHls = (function() { | ||
602 | var | ||
603 | video = document.createElement('video'), | ||
604 | xMpegUrl, | ||
605 | vndMpeg; | ||
606 | |||
607 | // native HLS is definitely not supported if HTML5 video isn't | ||
608 | if (!videojs.Html5.isSupported()) { | ||
609 | return false; | ||
610 | } | ||
611 | |||
612 | xMpegUrl = video.canPlayType('application/x-mpegURL'); | ||
613 | vndMpeg = video.canPlayType('application/vnd.apple.mpegURL'); | ||
614 | return (/probably|maybe/).test(xMpegUrl) || | ||
615 | (/probably|maybe/).test(vndMpeg); | ||
616 | })(); | ||
617 | |||
598 | // the desired length of video to maintain in the buffer, in seconds | 618 | // the desired length of video to maintain in the buffer, in seconds |
599 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; | 619 | videojs.Hls.GOAL_BUFFER_LENGTH = 30; |
600 | 620 | ||
... | @@ -628,7 +648,9 @@ videojs.Hls.prototype.duration = function() { | ... | @@ -628,7 +648,9 @@ videojs.Hls.prototype.duration = function() { |
628 | }; | 648 | }; |
629 | 649 | ||
630 | videojs.Hls.isSupported = function() { | 650 | videojs.Hls.isSupported = function() { |
631 | return videojs.Flash.isSupported() && videojs.MediaSource; | 651 | return !videojs.Hls.supportsNativeHls && |
652 | videojs.Flash.isSupported() && | ||
653 | videojs.MediaSource; | ||
632 | }; | 654 | }; |
633 | 655 | ||
634 | videojs.Hls.canPlaySource = function(srcObj) { | 656 | videojs.Hls.canPlaySource = function(srcObj) { |
... | @@ -757,6 +779,6 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) { | ... | @@ -757,6 +779,6 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) { |
757 | }; | 779 | }; |
758 | 780 | ||
759 | // Add HLS to the standard tech order | 781 | // Add HLS to the standard tech order |
760 | videojs.options.techOrder.push('hls'); | 782 | videojs.options.techOrder.unshift('hls'); |
761 | 783 | ||
762 | })(window, window.videojs, document); | 784 | })(window, window.videojs, document); | ... | ... |
... | @@ -28,6 +28,7 @@ var | ... | @@ -28,6 +28,7 @@ var |
28 | oldSetTimeout, | 28 | oldSetTimeout, |
29 | oldSourceBuffer, | 29 | oldSourceBuffer, |
30 | oldFlashSupported, | 30 | oldFlashSupported, |
31 | oldNativeHlsSupport, | ||
31 | requests, | 32 | requests, |
32 | xhr, | 33 | xhr, |
33 | 34 | ||
... | @@ -39,7 +40,6 @@ var | ... | @@ -39,7 +40,6 @@ var |
39 | flash: { | 40 | flash: { |
40 | swf: '' | 41 | swf: '' |
41 | }, | 42 | }, |
42 | techOrder: ['hls'], | ||
43 | hls: options || {} | 43 | hls: options || {} |
44 | }); | 44 | }); |
45 | 45 | ||
... | @@ -125,6 +125,8 @@ module('HLS', { | ... | @@ -125,6 +125,8 @@ module('HLS', { |
125 | oldSegmentParser = videojs.Hls.SegmentParser; | 125 | oldSegmentParser = videojs.Hls.SegmentParser; |
126 | oldSetTimeout = window.setTimeout; | 126 | oldSetTimeout = window.setTimeout; |
127 | 127 | ||
128 | oldNativeHlsSupport = videojs.Hls.supportsNativeHls; | ||
129 | |||
128 | // fake XHRs | 130 | // fake XHRs |
129 | xhr = sinon.useFakeXMLHttpRequest(); | 131 | xhr = sinon.useFakeXMLHttpRequest(); |
130 | requests = []; | 132 | requests = []; |
... | @@ -141,6 +143,7 @@ module('HLS', { | ... | @@ -141,6 +143,7 @@ module('HLS', { |
141 | videojs.Flash.isSupported = oldFlashSupported; | 143 | videojs.Flash.isSupported = oldFlashSupported; |
142 | videojs.MediaSource.open = oldMediaSourceOpen; | 144 | videojs.MediaSource.open = oldMediaSourceOpen; |
143 | videojs.Hls.SegmentParser = oldSegmentParser; | 145 | videojs.Hls.SegmentParser = oldSegmentParser; |
146 | videojs.Hls.supportsNativeHls = oldNativeHlsSupport; | ||
144 | videojs.SourceBuffer = oldSourceBuffer; | 147 | videojs.SourceBuffer = oldSourceBuffer; |
145 | window.setTimeout = oldSetTimeout; | 148 | window.setTimeout = oldSetTimeout; |
146 | xhr.restore(); | 149 | xhr.restore(); |
... | @@ -1207,4 +1210,21 @@ test('only supports HLS MIME types', function() { | ... | @@ -1207,4 +1210,21 @@ test('only supports HLS MIME types', function() { |
1207 | }), 'does not support flv'); | 1210 | }), 'does not support flv'); |
1208 | }); | 1211 | }); |
1209 | 1212 | ||
1213 | test('adds Hls to the default tech order', function() { | ||
1214 | strictEqual(videojs.options.techOrder[0], 'hls', 'first entry is Hls'); | ||
1215 | }); | ||
1216 | |||
1217 | test('has no effect if native HLS is available', function() { | ||
1218 | var player; | ||
1219 | videojs.Hls.supportsNativeHls = true; | ||
1220 | player = createPlayer(); | ||
1221 | player.src({ | ||
1222 | src: 'http://example.com/manifest/master.m3u8', | ||
1223 | type: 'application/x-mpegURL' | ||
1224 | }); | ||
1225 | |||
1226 | ok(!player.hls, 'did not load hls tech'); | ||
1227 | player.dispose(); | ||
1228 | }); | ||
1229 | |||
1210 | })(window, window.videojs); | 1230 | })(window, window.videojs); | ... | ... |
-
Please register or sign in to post a comment