diff --git a/src/js/tech/html5.js b/src/js/tech/html5.js index 4a8ea8e00d..edf79f8249 100644 --- a/src/js/tech/html5.js +++ b/src/js/tech/html5.js @@ -767,25 +767,7 @@ Html5.canControlPlaybackRate = function() { * @return {Boolean} */ Html5.supportsNativeTextTracks = function() { - let supportsTextTracks; - - // Figure out native text track support - // If mode is a number, we cannot change it because it'll disappear from view. - // Browsers with numeric modes include IE10 and older (<=2013) samsung android models. - // Firefox isn't playing nice either with modifying the mode - // TODO: Investigate firefox: https://github.com/videojs/video.js/issues/1862 - supportsTextTracks = !!Html5.TEST_VID.textTracks; - if (supportsTextTracks && Html5.TEST_VID.textTracks.length > 0) { - supportsTextTracks = typeof Html5.TEST_VID.textTracks[0].mode !== 'number'; - } - if (supportsTextTracks && browser.IS_FIREFOX) { - supportsTextTracks = false; - } - if (supportsTextTracks && !('onremovetrack' in Html5.TEST_VID.textTracks)) { - supportsTextTracks = false; - } - - return supportsTextTracks; + return browser.IS_ANY_SAFARI; }; /** diff --git a/src/js/utils/browser.js b/src/js/utils/browser.js index 9220972d50..cd52242e83 100644 --- a/src/js/utils/browser.js +++ b/src/js/utils/browser.js @@ -66,5 +66,8 @@ export const IE_VERSION = (function(result) { return result && parseFloat(result[1]); }((/MSIE\s(\d+)\.\d/).exec(USER_AGENT))); +export const IS_SAFARI = (/Safari/i).test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE; +export const IS_ANY_SAFARI = IS_SAFARI || IS_IOS; + export const TOUCH_ENABLED = !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch); export const BACKGROUND_SIZE_SUPPORTED = 'backgroundSize' in document.createElement('video').style; diff --git a/test/unit/tracks/text-tracks.test.js b/test/unit/tracks/text-tracks.test.js index df53357535..1f6e849ce7 100644 --- a/test/unit/tracks/text-tracks.test.js +++ b/test/unit/tracks/text-tracks.test.js @@ -250,37 +250,24 @@ QUnit.test('if native text tracks are not supported, create a texttrackdisplay', player.dispose(); }); -QUnit.test('html5 tech supports native text tracks if the video supports it, unless mode is a number', function(assert) { +QUnit.test('emulated tracks are always used, except in safari', function(assert) { const oldTestVid = Html5.TEST_VID; + const oldIsAnySafari = browser.IS_ANY_SAFARI; Html5.TEST_VID = { - textTracks: [{ - mode: 0 - }] + textTracks: [] }; - assert.ok(!Html5.supportsNativeTextTracks(), - 'native text tracks are not supported if mode is a number'); - - Html5.TEST_VID = oldTestVid; -}); - -QUnit.test('html5 tech supports native text tracks if the video supports it, unless it is firefox', function(assert) { - const oldTestVid = Html5.TEST_VID; - const oldIsFirefox = browser.IS_FIREFOX; + browser.IS_ANY_SAFARI = false; - Html5.TEST_VID = { - textTracks: [] - }; + assert.ok(!Html5.supportsNativeTextTracks(), 'Html5 does not support native text tracks, in non-safari'); - browser.IS_FIREFOX = true; + browser.IS_ANY_SAFARI = true; - assert.ok(!Html5.supportsNativeTextTracks(), - 'if textTracks are available on video element,' + - ' native text tracks are supported'); + assert.ok(Html5.supportsNativeTextTracks(), 'Html5 does support native text tracks in safari'); Html5.TEST_VID = oldTestVid; - browser.IS_FIREFOX = oldIsFirefox; + browser.IS_ANY_SAFARI = oldIsAnySafari; }); QUnit.test('when switching techs, we should not get a new text track', function(assert) {