diff --git a/build/types/core b/build/types/core index 20808d172c..488407a280 100644 --- a/build/types/core +++ b/build/types/core @@ -61,6 +61,7 @@ +../../lib/text/cue.js +../../lib/text/simple_text_displayer.js ++../../lib/text/stub_text_displayer.js +../../lib/text/text_engine.js +../../lib/text/text_utils.js +../../lib/text/ui_text_displayer.js diff --git a/lib/player.js b/lib/player.js index f50776d56a..d671632e30 100644 --- a/lib/player.js +++ b/lib/player.js @@ -34,6 +34,7 @@ goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.net.NetworkingUtils'); goog.require('shaka.routing.Walker'); goog.require('shaka.text.SimpleTextDisplayer'); +goog.require('shaka.text.StubTextDisplayer'); goog.require('shaka.text.TextEngine'); goog.require('shaka.text.UITextDisplayer'); goog.require('shaka.text.WebVttGenerator'); @@ -5445,7 +5446,14 @@ shaka.Player = class extends shaka.util.FakeEventTarget { return new shaka.text.UITextDisplayer( this.video_, this.videoContainer_); } else { - return new shaka.text.SimpleTextDisplayer(this.video_); + // eslint-disable-next-line no-restricted-syntax + if (HTMLMediaElement.prototype.addTextTrack) { + return new shaka.text.SimpleTextDisplayer(this.video_); + } else { + shaka.log.warning('Text tracks are not supported by the ' + + 'browser, disabling.'); + return new shaka.text.StubTextDisplayer(); + } } }; return config; diff --git a/lib/text/stub_text_displayer.js b/lib/text/stub_text_displayer.js new file mode 100644 index 0000000000..785e06a2a3 --- /dev/null +++ b/lib/text/stub_text_displayer.js @@ -0,0 +1,51 @@ +/*! @license + * Shaka Player + * Copyright 2023 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +goog.provide('shaka.text.StubTextDisplayer'); + +/** +* A stub text displayer plugin that does nothing +* +* @implements {shaka.extern.TextDisplayer} +* @export +*/ +shaka.text.StubTextDisplayer = class { + /** + * @override + * @export + */ + remove(start, end) { + } + + /** + * @override + * @export + */ + append(cues) { + } + + /** + * @override + * @export + */ + destroy() { + } + + /** + * @override + * @export + */ + isTextVisible() { + return false; + } + + /** + * @override + * @export + */ + setTextVisibility(on) { + } +};