From 7203a05b1e486be46762c504ebb69cd2bd3c279a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 13 Nov 2024 17:54:38 +0100 Subject: [PATCH] fix: Prefer SimpleTextDisplayer on iOS (#7569) Fixes https://github.com/shaka-project/shaka-player/issues/7568 --- lib/player.js | 7 ++++++- lib/text/ui_text_displayer.js | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/player.js b/lib/player.js index 3943a71fb4..6195b90111 100644 --- a/lib/player.js +++ b/lib/player.js @@ -5922,7 +5922,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget { // Because this.video_ may not be set when the config is built, the default // TextDisplay factory must capture a reference to "this". config.textDisplayFactory = () => { - if (this.videoContainer_) { + // On iOS where the Fullscreen API is not available we prefer + // SimpleTextDisplayer because it works with the Fullscreen API of the + // video element itself. + const Platform = shaka.util.Platform; + if (this.videoContainer_ && + (!Platform.safariVersion() || document.fullscreenEnabled)) { const latestConfig = this.getConfiguration(); return new shaka.text.UITextDisplayer( this.video_, this.videoContainer_, latestConfig.textDisplayer); diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 3c9c0974c4..fa95ef2e06 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -9,6 +9,7 @@ goog.provide('shaka.text.UITextDisplayer'); goog.require('goog.asserts'); goog.require('shaka.Deprecate'); +goog.require('shaka.log'); goog.require('shaka.text.Cue'); goog.require('shaka.text.CueRegion'); goog.require('shaka.text.Utils'); @@ -35,6 +36,12 @@ shaka.text.UITextDisplayer = class { constructor(video, videoContainer, config) { goog.asserts.assert(videoContainer, 'videoContainer should be valid.'); + if (!document.fullscreenEnabled) { + shaka.log.alwaysWarn('Using UITextDisplayer in a browser without ' + + 'Fullscreen API support causes subtitles to not be rendered in ' + + 'fullscreen'); + } + /** @private {boolean} */ this.isTextVisible_ = false;