Native HLS check shouldn't fail if HTML5 video isn't supported
Check if HTML video is available before trying to call canPlayType for HLS mime types.
Showing
2 changed files
with
18 additions
and
7 deletions
... | @@ -15,9 +15,18 @@ videojs.hls = { | ... | @@ -15,9 +15,18 @@ videojs.hls = { |
15 | supportsNativeHls: (function() { | 15 | supportsNativeHls: (function() { |
16 | var | 16 | var |
17 | video = document.createElement('video'), | 17 | video = document.createElement('video'), |
18 | xMpegUrl = video.canPlayType('application/x-mpegURL'), | 18 | xMpegUrl, |
19 | vndMpeg = video.canPlayType('application/vnd.apple.mpegURL'); | 19 | vndMpeg; |
20 | return /probably|maybe/.test(xMpegUrl) || /probably|maybe/.test(vndMpeg); | 20 | |
21 | // native HLS is definitely not supported if HTML5 video isn't | ||
22 | if (!videojs.Html5.isSupported()) { | ||
23 | return false; | ||
24 | } | ||
25 | |||
26 | xMpegUrl = video.canPlayType('application/x-mpegURL'); | ||
27 | vndMpeg = video.canPlayType('application/vnd.apple.mpegURL'); | ||
28 | return (/probably|maybe/).test(xMpegUrl) || | ||
29 | (/probably|maybe/).test(vndMpeg); | ||
21 | })() | 30 | })() |
22 | }; | 31 | }; |
23 | 32 | ... | ... |
... | @@ -26,6 +26,7 @@ var | ... | @@ -26,6 +26,7 @@ var |
26 | oldFlashSupported, | 26 | oldFlashSupported, |
27 | oldXhr, | 27 | oldXhr, |
28 | oldSourceBuffer, | 28 | oldSourceBuffer, |
29 | oldSupportsNativeHls, | ||
29 | xhrUrls; | 30 | xhrUrls; |
30 | 31 | ||
31 | module('HLS', { | 32 | module('HLS', { |
... | @@ -41,6 +42,10 @@ module('HLS', { | ... | @@ -41,6 +42,10 @@ module('HLS', { |
41 | this.appendBuffer = function() {}; | 42 | this.appendBuffer = function() {}; |
42 | }; | 43 | }; |
43 | 44 | ||
45 | // force native HLS to be ignored | ||
46 | oldSupportsNativeHls = videojs.hls.supportsNativeHls; | ||
47 | videojs.hls.supportsNativeHls = false; | ||
48 | |||
44 | // create the test player | 49 | // create the test player |
45 | var video = document.createElement('video'); | 50 | var video = document.createElement('video'); |
46 | document.querySelector('#qunit-fixture').appendChild(video); | 51 | document.querySelector('#qunit-fixture').appendChild(video); |
... | @@ -78,6 +83,7 @@ module('HLS', { | ... | @@ -78,6 +83,7 @@ module('HLS', { |
78 | }, | 83 | }, |
79 | teardown: function() { | 84 | teardown: function() { |
80 | videojs.Flash.isSupported = oldFlashSupported; | 85 | videojs.Flash.isSupported = oldFlashSupported; |
86 | videojs.hls.supportsNativeHls = oldSupportsNativeHls; | ||
81 | window.videojs.SourceBuffer = oldSourceBuffer; | 87 | window.videojs.SourceBuffer = oldSourceBuffer; |
82 | window.XMLHttpRequest = oldXhr; | 88 | window.XMLHttpRequest = oldXhr; |
83 | } | 89 | } |
... | @@ -631,15 +637,11 @@ test('segment 500 should trigger MEDIA_ERR_ABORTED', function () { | ... | @@ -631,15 +637,11 @@ test('segment 500 should trigger MEDIA_ERR_ABORTED', function () { |
631 | }); | 637 | }); |
632 | 638 | ||
633 | test('has no effect if native HLS is available', function() { | 639 | test('has no effect if native HLS is available', function() { |
634 | var supported = videojs.hls.supportsNativeHls; | ||
635 | videojs.hls.supportsNativeHls = true; | 640 | videojs.hls.supportsNativeHls = true; |
636 | player.hls('manifest/master.m3u8'); | 641 | player.hls('manifest/master.m3u8'); |
637 | 642 | ||
638 | ok(!(player.currentSrc() in videojs.mediaSources), | 643 | ok(!(player.currentSrc() in videojs.mediaSources), |
639 | 'no media source was opened'); | 644 | 'no media source was opened'); |
640 | |||
641 | // clean up | ||
642 | videojs.hls.supportsNativeHls = supported; | ||
643 | }); | 645 | }); |
644 | 646 | ||
645 | module('segment controller', { | 647 | module('segment controller', { | ... | ... |
-
Please register or sign in to post a comment