Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Watermark Support to Shaka Player UI #7877

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bd5227a
add static and dynamic watermark
chafroudtarek Dec 5, 2024
876b230
Fix: Remove unused file demoTest
chafroudtarek Jan 10, 2025
2696e94
docs: add Tarek Chafroud to AUTHORS and CONTRIBUTORS
chafroudtarek Jan 10, 2025
0ee73b0
chore: clean up unused and redundant code
chafroudtarek Jan 10, 2025
a51bb75
docs: add Apache-2.0 license header
chafroudtarek Jan 10, 2025
469ab8d
fix: break long lines to adhere to max-len rule
chafroudtarek Jan 10, 2025
c1da5c9
fix: correct indentation issues in codebase
chafroudtarek Jan 10, 2025
f156d4e
refactor(watermark): centralize canvas 2d context error handling
chafroudtarek Jan 13, 2025
f9ff56f
refactor(watermark): move API docs to JSDoc
chafroudtarek Jan 13, 2025
d8862b3
refactor(styles): move watermark styles to dedicated less file
chafroudtarek Jan 13, 2025
d66e412
refactor(watermark): replace window.resize with ResizeObserver
chafroudtarek Jan 13, 2025
fdc913d
refactor(ui): move watermark options to extern
chafroudtarek Jan 13, 2025
0683a1e
refactor(ui): move watermark options to ui externs
chafroudtarek Jan 13, 2025
1e58c8a
feat(ui): enhance dynamic watermark with fade transitions
chafroudtarek Jan 13, 2025
b5fec73
docs(ui): improve watermark options documentation formatting
chafroudtarek Jan 13, 2025
5f00860
fix: Ensure correct parameter type for setTextWatermark in Shaka UI a…
chafroudtarek Jan 13, 2025
0a66512
fix: Ensure correct parameter type for setTextWatermark in Shaka UI a…
chafroudtarek Jan 13, 2025
4c32838
fix : add the empty line
chafroudtarek Jan 13, 2025
c270f64
refactor: convert watermark timing values from milliseconds to seconds
chafroudtarek Jan 13, 2025
12e765e
refactor: Apply watermark demo patch
chafroudtarek Jan 13, 2025
4dd5a13
fix: add line at the end of ui.js
chafroudtarek Jan 14, 2025
586e123
test: Fix config and watermark tests
chafroudtarek Jan 14, 2025
e05dce4
test: Add missing config field exceptions to demo_unit.js
chafroudtarek Jan 14, 2025
157dd29
revert: remove added configuration fields
chafroudtarek Jan 14, 2025
83f08ff
fix: lint issue in demo_unit.js
chafroudtarek Jan 14, 2025
930d5bf
fix: lint issue in demo_unit.js
chafroudtarek Jan 14, 2025
c23da35
revert: removed missing code from demo_unit.js
chafroudtarek Jan 14, 2025
cfe51b0
revert: removed missing spaces from demo_unit.js
chafroudtarek Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,4 @@ Koen Romers <koenromers@gmail.com>
Zhenghang Chen <czhtju@gmail.com>
Ashley Manners <ashley.manners@xperi.com>
Bidisha Das <officialbidisha1@gmail.com>
Chafroud Tarek <chafroudtarek3@gmail.com>
2 changes: 2 additions & 0 deletions build/types/ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
+../../ui/ad_statistics_button.js
+../../ui/audio_language_selection.js
+../../ui/externs/ui.js
+../../ui/externs/watermark.js
+../../ui/play_button.js
+../../ui/big_play_button.js
+../../ui/airplay_button.js
Expand Down Expand Up @@ -50,5 +51,6 @@
+../../ui/vr_utils.js
+../../ui/vr_webgl.js

+../../ui/watermark.js
+../../ui/gl_matrix/matrix_4x4.js
+../../ui/gl_matrix/matrix_quaternion.js
1 change: 1 addition & 0 deletions ui/controls.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import "less/ad_controls.less";
@import "less/tooltip.less";
@import "less/thumbnails.less";
@import "less/watermark.less";
@import (css, inline) "https://fonts.googleapis.com/css?family=Roboto";
// NOTE: Working around google/material-design-icons#958
@import (css, inline) "https://fonts.googleapis.com/icon?family=Material+Icons+Round";
64 changes: 64 additions & 0 deletions ui/externs/watermark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/


/**
* @externs
* @suppress {duplicate} To prevent compiler errors with the namespace
* being declared both here and by goog.provide in the library.
*/


/**
* @typedef {{
* type: string,
* text: string,
* position: string,
* color: string,
* size: number,
* alpha: number,
* interval: number,
* skip: number,
* displayDuration: number,
* transitionDuration: number
* }}
*
* @property {string} type
* The type of watermark ('static' or 'dynamic').
* Defaults to 'static'.
* @property {string} text
* The text content of the watermark. Required.
* @property {string} position
* Position of the watermark.
* Defaults to 'top-left'.
* @property {string} color
* The color of the watermark text.
* Defaults to 'white'.
* @property {number} size
* Font size of the watermark text in pixels.
* Defaults to 24.
* @property {number} alpha
* Opacity of the watermark (0.0 to 1.0).
* Defaults to 0.7.
* @property {number} interval
* Interval between position updates for dynamic watermarks (in milliseconds).
* Only used when type is 'dynamic'.
* Defaults to 2000.
* @property {number} skip
* Skip duration for dynamic watermarks (in milliseconds).
* Only used when type is 'dynamic'.
* Defaults to 500.
* @property {number} displayDuration
* Duration to display watermark at each position (in seconds).
* Only used when type is 'dynamic'.
* Defaults to 3.
* @property {number} transitionDuration
* Duration of fade transitions between positions (in seconds).
* Only used when type is 'dynamic'.
* Defaults to 0.5.
* @exportDoc
*/
shaka.ui.Watermark.Options;
46 changes: 46 additions & 0 deletions ui/less/watermark.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/* Styles for watermark components in the UI. */

/* Container that holds all watermark elements */
.shaka-watermark-container {
position: absolute;
pointer-events: none;
z-index: 1;
width: 100%;
height: 100%;

/* Ensure watermarks don't interfere with video interactions */
.unselectable();
}

/* Text-based watermark styling */
.shaka-text-watermark {
position: absolute;
color: white;
font-size: 24px;

/* Add subtle text shadow for better visibility */
text-shadow: 2px 2px 2px rgba(0, 0, 0, 50%);
opacity: 0.5;

/* Ensure text is crisp */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

/* Image-based watermark styling */
.shaka-image-watermark {
position: absolute;
max-width: 150px;
max-height: 150px;
opacity: 0.5;

/* Ensure smooth scaling */
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
31 changes: 30 additions & 1 deletion ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ goog.require('shaka.Player');
goog.require('shaka.log');
goog.require('shaka.polyfill');
goog.require('shaka.ui.Controls');
goog.require('shaka.ui.Watermark');
goog.require('shaka.util.ConfigUtils');
goog.require('shaka.util.Dom');
goog.require('shaka.util.FakeEvent');
Expand Down Expand Up @@ -66,6 +67,13 @@ shaka.ui.Overlay = class {

videoContainer['ui'] = this;
video['ui'] = this;

/** @private {shaka.ui.Watermark} */

this.watermark_ = new shaka.ui.Watermark(
this.videoContainer_,
this.controls_,
);
}


Expand All @@ -83,6 +91,7 @@ shaka.ui.Overlay = class {
await this.player_.destroy();
}
this.player_ = null;
this.watermark_ = null;
}


Expand Down Expand Up @@ -168,6 +177,27 @@ shaka.ui.Overlay = class {
}


/**
* @param {string} text
* @param {shaka.ui.Watermark.Options=} options
* @export
*/
setTextWatermark(text, options) {
if (this.watermark_) {
this.watermark_.setTextWatermark(text, options);
}
}

/**
* @export
*/
removeWatermark() {
if (this.watermark_) {
this.watermark_.removeWatermark();
}
}


/**
* @return {!shaka.extern.UIConfiguration}
* @private
Expand Down Expand Up @@ -593,4 +623,3 @@ if (document.readyState == 'complete') {
} else {
window.addEventListener('load', shaka.ui.Overlay.scanPageForShakaElements_);
}

Loading
Loading