From 8d4f9a492bb55c8765890348da406b2969f93925 Mon Sep 17 00:00:00 2001 From: Sandra Lokshina Date: Thu, 29 Aug 2019 13:13:20 -0700 Subject: [PATCH] Add config for using src= on Safari. Closes #2116. Change-Id: I4742037563a20e2e585a6dfbeae29a65bffe2117 --- externs/shaka/player.js | 8 +++++++- lib/player.js | 7 +++---- lib/util/platform.js | 1 + lib/util/player_configuration.js | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/externs/shaka/player.js b/externs/shaka/player.js index 6b64f9cdcf..992328cc3c 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -639,7 +639,8 @@ shaka.extern.ManifestConfiguration; * safeSeekOffset: number, * stallEnabled: boolean, * stallThreshold: number, - * stallSkip: number + * stallSkip: number, + * useNativeHlsOnSafari: boolean * }} * * @description @@ -715,6 +716,11 @@ shaka.extern.ManifestConfiguration; * @property {number} stallSkip * The number of seconds that the player will skip forward when a stall has * been detected. + * @property {boolean} useNativeHlsOnSafari + * Desktop Safari has both MediaSource and their native HLS implementation. + * Depending on the application's needs, it may prefer one over the other. + * Examples: FairPlay is only supported via Safari's native HLS, but it + * doesn't have an API for selecting specific tracks. * @exportDoc */ shaka.extern.StreamingConfiguration; diff --git a/lib/player.js b/lib/player.js index fa4117bb63..998c97aaa8 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1088,10 +1088,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget { // We would prefer MediaSource in some cases, and src= in others. For // example, Android has native HLS, but we'd prefer our own MediaSource - // version there. But for Safari desktop, we'd prefer the native one for - // now, because that's the only way we get FairPlay there. So use src= - // over MSE on any Apple platform. - return Platform.isApple(); + // version there. For Safari, the choice is governed by the + // useNativeHlsOnSafari setting of the streaming config. + return Platform.isApple() && this.config_.streaming.useNativeHlsOnSafari; } // Unless there are good reasons to use src= (single-file playback or native diff --git a/lib/util/platform.js b/lib/util/platform.js index 7b7408df69..2ae6bb8cc2 100644 --- a/lib/util/platform.js +++ b/lib/util/platform.js @@ -126,6 +126,7 @@ shaka.util.Platform = class { !shaka.util.Platform.isEdge(); } + /** * Check if the current platform is an Apple device (iOS, desktop Safari, etc) * diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index b4f1e3a8df..26f307c5c2 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -131,6 +131,7 @@ shaka.util.PlayerConfiguration = class { stallEnabled: true, stallThreshold: 1 /* seconds */, stallSkip: 0.1 /* seconds */, + useNativeHlsOnSafari: true, }; // WebOS has a long hardware pipeline that responds slowly, making it easy