Skip to content

Commit

Permalink
feat: Add a stub text display class (shaka-project#5804)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidokert committed Oct 25, 2023
1 parent 51870e9 commit c9ee316
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions build/types/core
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions lib/text/stub_text_displayer.js
Original file line number Diff line number Diff line change
@@ -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) {
}
};

0 comments on commit c9ee316

Please sign in to comment.