From 225d1278a48f6be600c08638380219a2915c578c Mon Sep 17 00:00:00 2001 From: Ileana Padilla Date: Wed, 10 Jun 2020 16:08:04 -0500 Subject: [PATCH] feat: Use VHS playback on any non-Safari browser (#843) Do a check for videojs.browser.IS_ANY_SAFARI and use that for overrideNative so that we use VHS playback on any non-safari browser. Co-authored-by: ipadilla4 Co-authored-by: Garrett Singer --- src/videojs-http-streaming.js | 2 +- test/videojs-http-streaming.test.js | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/videojs-http-streaming.js b/src/videojs-http-streaming.js index 2904879c..1839b436 100644 --- a/src/videojs-http-streaming.js +++ b/src/videojs-http-streaming.js @@ -879,7 +879,7 @@ const HlsSourceHandler = { return tech.hls; }, canPlayType(type, options = {}) { - const { hls: { overrideNative } } = videojs.mergeOptions(videojs.options, options); + const { hls: { overrideNative = !videojs.browser.IS_ANY_SAFARI } } = videojs.mergeOptions(videojs.options, options); const supportedType = simpleTypeFromSourceType(type); const canUseMsePlayback = supportedType && (!Hls.supportsTypeNatively(supportedType) || overrideNative); diff --git a/test/videojs-http-streaming.test.js b/test/videojs-http-streaming.test.js index 2e406b03..da3ef118 100644 --- a/test/videojs-http-streaming.test.js +++ b/test/videojs-http-streaming.test.js @@ -2839,10 +2839,12 @@ QUnit.test( } ); -QUnit.test('has no effect if native HLS is available', function(assert) { +QUnit.test('has no effect if native HLS is available and browser is Safari', function(assert) { const Html5 = videojs.getTech('Html5'); const oldHtml5CanPlaySource = Html5.canPlaySource; + const origIsAnySafari = videojs.browser.IS_ANY_SAFARI; + videojs.browser.IS_ANY_SAFARI = true; Html5.canPlaySource = () => true; Hls.supportsNativeHls = true; const player = createPlayer(); @@ -2857,6 +2859,30 @@ QUnit.test('has no effect if native HLS is available', function(assert) { assert.ok(!player.tech_.hls, 'did not load hls tech'); player.dispose(); Html5.canPlaySource = oldHtml5CanPlaySource; + videojs.browser.IS_ANY_SAFARI = origIsAnySafari; +}); + +QUnit.test('loads if native HLS is available but browser is not Safari', function(assert) { + const Html5 = videojs.getTech('Html5'); + const oldHtml5CanPlaySource = Html5.canPlaySource; + const origIsAnySafari = videojs.browser.IS_ANY_SAFARI; + + videojs.browser.IS_ANY_SAFARI = false; + Html5.canPlaySource = () => true; + Hls.supportsNativeHls = true; + const player = createPlayer(); + + player.src({ + src: 'http://example.com/manifest/master.m3u8', + type: 'application/x-mpegURL' + }); + + this.clock.tick(1); + + assert.ok(player.tech_.hls, 'loaded hls tech'); + player.dispose(); + Html5.canPlaySource = oldHtml5CanPlaySource; + videojs.browser.IS_ANY_SAFARI = origIsAnySafari; }); QUnit.test(