Skip to main content

Watermarks

Display one or more text and image watermarks over video playback by passing BaseWatermarkConfig entries (TextWatermarkConfig and ImageWatermarkConfig) to setWatermarks(_:). Watermarks render above the video and subtitles but below the player controls on both SwiftUI and UIKit paths. Pass an empty list to remove all watermarks.

Migration Notice

WatermarkConfig is currently retained as a typealias for backward compatibility. Please update your code to use TextWatermarkConfig, as WatermarkConfig will be deprecated in upcoming releases.

Usage

import TPStreamsSDK

let config = TPStreamPlayerConfigurationBuilder()
.setWatermarks([
// Animated text watermark
TextWatermarkConfig(
text: "user@example.com",
x: 0,
y: 50,
color: 0xFFFFFFFF,
textSize: 16,
opacity: 0.5,
animation: WatermarkAnimation(type: .pingPong, duration: 10000)
),
// Static text watermark
TextWatermarkConfig(
text: "CONFIDENTIAL",
x: 50,
y: 10,
color: 0xFFFF0000,
textSize: 14,
opacity: 0.3
),
// Image watermark (e.g., instructor avatar or brand logo)
ImageWatermarkConfig(
imageUrl: "https://example.com/branding/logo.png",
width: 48,
height: 48,
x: 92,
y: 88,
opacity: 1.0
)
])
.build()

On iOS, watermarks are defined via configuration. On the UIKit path, you can mutate TPStreamPlayerViewController.config.watermarks at runtime to update or re-apply them without recreating the player.


Configuration Types

Both text and image watermark configurations conform to BaseWatermarkConfig.

TextWatermarkConfig Properties

Use TextWatermarkConfig to overlay text strings (e.g., user email, ID, or notice) for content protection.

PropertyTypeDefaultDescription
textStringWatermark text (required)
xInt640Horizontal position as a percentage of the player view width (0100)
yInt640Vertical position as a percentage of the player view height (0100)
colorInt640xFFFFFFFFWatermark text color as an ARGB integer value (default: white)
textSizeDouble14Text size in points
opacityDouble0.3Opacity from 0.0 (transparent) to 1.0 (opaque)
animationWatermarkAnimation?nilOptional animation; nil renders a static watermark

ImageWatermarkConfig Properties

Use ImageWatermarkConfig to display remote image overlays such as instructor avatars or company branding.

PropertyTypeDefaultDescription
imageUrlStringHTTPS URL of the watermark image (required, PNG recommended)
widthDouble48Width in points (clamped to >= 0)
heightDouble48Height in points (clamped to >= 0)
xInt6492Horizontal position percentage (0100, default places towards bottom-right)
yInt6488Vertical position percentage (0100, default places towards bottom-right)
opacityDouble1.0Opacity from 0.0 (transparent) to 1.0 (opaque)

WatermarkAnimation / WatermarkAnimationType

WatermarkAnimation is supported on TextWatermarkConfig and accepts type (WatermarkAnimationType) and duration in milliseconds (default 10000, minimum 100).

Supported animation types:

  • pingPong (.pingPong): Moves the watermark horizontally from the left edge to the right edge and back, taking the configured duration per leg. Animated watermarks ignore the initial x coordinate; their y position is honored.
  • random (.random): Repositions the watermark to random coordinates across the active player view every duration milliseconds. Both x and y initial coordinates are randomized.

Behavior & Features

  • Asynchronous Image Loading & Caching: Remote images in ImageWatermarkConfig are fetched asynchronously and cached for smooth rendering.
  • Controls Auto-Hide: Image watermark overlays automatically fade out when player controls are visible and smoothly fade back in when controls are dismissed.
  • Safe Positioning & Boundary Clamping: Watermarks are kept fully visible inside the player view with a fixed inset, and automatically reposition on screen rotation, fullscreen transitions, and view resizing. Out-of-range x/y (0100) and opacity (0.01.0) values are clamped to the nearest bound.
  • Playback Sync: Animated text watermarks pause while playback is not active (paused, buffering, ended) and resume smoothly from the paused position when playback resumes.
  • Lifecycle Cleanup: Overlays and running animation timers are cleanly torn down when the player view controller is deinitialized.