Merge pull request #94 from videojs/feature/auto-tech-order
Rebased update-options
Showing
4 changed files
with
50 additions
and
14 deletions
... | @@ -12,11 +12,8 @@ Download the [Media Source plugin](https://github.com/videojs/videojs-contrib-me | ... | @@ -12,11 +12,8 @@ Download the [Media Source plugin](https://github.com/videojs/videojs-contrib-me |
12 | <script src="videojs-media-sources.js"></script> | 12 | <script src="videojs-media-sources.js"></script> |
13 | <script src="videojs-hls.min.js"></script> | 13 | <script src="videojs-hls.min.js"></script> |
14 | <script> | 14 | <script> |
15 | var player = videojs('test-vid', { | 15 | var player = videojs('test-vid'); |
16 | techOrder: ['html5', 'hls', 'flash'] | 16 | player.play(); |
17 | }, function() { | ||
18 | this.play(); | ||
19 | }); | ||
20 | </script> | 17 | </script> |
21 | ``` | 18 | ``` |
22 | 19 | ||
... | @@ -60,7 +57,6 @@ other tech: | ... | @@ -60,7 +57,6 @@ other tech: |
60 | 57 | ||
61 | ```javascript | 58 | ```javascript |
62 | videojs(video, { | 59 | videojs(video, { |
63 | techOrder: ['hls'], | ||
64 | hls: { | 60 | hls: { |
65 | withCredentials: true | 61 | withCredentials: true |
66 | } | 62 | } | ... | ... |
... | @@ -63,12 +63,7 @@ | ... | @@ -63,12 +63,7 @@ |
63 | <script> | 63 | <script> |
64 | videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf'; | 64 | videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf'; |
65 | // initialize the player | 65 | // initialize the player |
66 | var player = videojs('video', { | 66 | var player = videojs('video'); |
67 | techOrder: ['hls'] | ||
68 | }); | ||
69 | |||
70 | // initialize the plugin | ||
71 | //player.hls() | ||
72 | </script> | 67 | </script> |
73 | </body> | 68 | </body> |
74 | </html> | 69 | </html> | ... | ... |
... | @@ -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) { |
... | @@ -756,4 +778,7 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) { | ... | @@ -756,4 +778,7 @@ resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) { |
756 | return result; | 778 | return result; |
757 | }; | 779 | }; |
758 | 780 | ||
781 | // Add HLS to the standard tech order | ||
782 | videojs.options.techOrder.unshift('hls'); | ||
783 | |||
759 | })(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