Skip to content

Module: src/ui/UI

The UI component serves as the parent container for all UI-related elements within the video player. It manages the display of the interface by providing auto-hide and show functionality based on user interactions and timeouts. Additionally, it implements basic responsive design features, allowing CSS and other components to adapt the layout based on viewport size changes.

Version
1.1.0
Author
Frank Kudermann - alphanull
License
MIT
Requires
DomSmith
Source
UI.js, line 13

Constructor

new UI(player, parent, optionsopt)

Creates an instance of the UI component.

Parameters:
Name Type Attributes Description
player Player

Reference to the VisionPlayer instance.

parent Player

Reference to the parent instance.

options Object optional

Additional options.

Parameters:
Name Type Attributes Description
apiKey symbol optional

Token for extended access to the player API.

Members

Holds the instance configuration for this component.

Properties
Name Type Attributes Default Description
alwaysVisible boolean optional false

If true, the UI never auto-hides.

autoHide number optional 5

Time (in seconds) after which the UI auto-hides (0 disables).

clickToPlay boolean optional true

If true, clicking on the video element toggles play/pause.

showScaleSlider boolean optional true

If true, the UI scale slider is shown in the settings popup.

iconStyle string optional 'default'

The style of the icons: 'default' or 'filled'.

uiScale number optional 1

Initial scale factor for the UI.

Type
Object
Source
UI.js, line 25

Reference to the main player instance.

Type
Player
Source
UI.js, line 38

Holds tokens of subscriptions to player events, for later unsubscribe.

Type
Array<number>
Source
UI.js, line 44

Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.

Type
symbol
Source
UI.js, line 51

The root element in which the UI is placed.

Type
HTMLElement
Source
UI.js, line 57

Reference to the settings popup component.

Type
DomSmith | undefined
Source
UI.js, line 69

Reflects the state of the UI.

Properties
Name Type Description
state string

The UI's current state: 'visible' or 'hidden'.

hasFocus boolean | string

Reflects whether the video player currently has focus and which type of element has focus.

playerWidth number

Current known width of the player's container.

playerHeight number

Current known height of the player's container.

lastInput string

Type of last user interaction: mouseor touch.

Type
Object
Source
UI.js, line 80

Resize Observer, used for resize functionality (uses standard resize event if API not available).

Type
ResizeObserver
Source
UI.js, line 93

Flag indicating that the next tap is only meant to reveal the UI.

Type
boolean
Source
UI.js, line 99

The ID for a pending hide timer.

Type
number
Source
UI.js, line 105

Flag indicating if the UI is initialized.

Type
boolean
Source
UI.js, line 111

Methods

private #onDomReady()

Called when the player has fully initialized to set up UI.

Listens
dom/ready
Source
UI.js, line 176

private #onDataReady()

Called when the data is ready to set up UI.

Listens
data/ready
Source
UI.js, line 225

private #setUiScale(event)

Sets the UI scale.

Parameters:
Name Type Description
event InputEvent

The input event which called this handler.

Source
UI.js, line 239

private #onTogglePlay(event)

Handles toggle between play and pause when the user interacts with the UI. On touch devices, the first tap reveals the UI without toggling playback. The second tap (while UI is visible) will then toggle play/pause as expected.

Parameters:
Name Type Description
event PointerEvent

The pointerdown event that triggered the handler.

Source
UI.js, line 257

private #show(event)

Fires "ui/show" event, and removes the "hidden" class from the UI wrapper element.

Parameters:
Name Type Description
event Event

The event which called this handler.

Fires
ui/show
Source
UI.js, line 278

private #hide(event)

Fires "ui/hide" event, and adds a "hidden" class to the UI wrapper element.

Parameters:
Name Type Description
event Event

The event which called this handler.

Fires
ui/hide
Source
UI.js, line 298

private #enableAutoHide()

Enables "autohide" funtionality. Might be called via the player API, for example to enable autohiding again when a popup is closed.

Listens
popup/hide
Source
UI.js, line 312

private #disableAutoHide()

Disables "autohide" funtionality. Might be called via the player API, for example to prevent autohiding when a popup is open.

Listens
popup/show
Source
UI.js, line 327

private #enable()

Enables (auto)hiding and clickToPlay.

Fires
ui/enabled
Source
UI.js, line 341

private #disable()

Disables (auto)hiding and clickToPlay.

Fires
ui/disabled
Source
UI.js, line 368

private #enableClickPlay()

Enables the "click to play" functionality. This method listens to canplay events inorder to restore a usable state again when the player recovered from a media error (for example by loading another file).

Listens
media/canplay
Source
UI.js, line 391

private #disableClickPlay()

Disables "click to play" funtionality.

Listens
media/error
Source
UI.js, line 407

private #onRefreshTimer()

Resets the UI auto-hide timer on pointer interactions.

Source
UI.js, line 422

private #onFocus()

Helper function called when the videoplayer has focus. Used mainly for determining if the playerr should process keyboard events.

Source
UI.js, line 433

private #onInput(event)

Reacts to pointerdown and keyboard events to determine the last input method, which is exposed on the players state.

Parameters:
Name Type Description
event PointerEvent | KeyboardEvent

The pointer or keyboard event.

Source
UI.js, line 454

private #resize(entriesopt)

The resize handler provides basic "responsive design" functionality. As the player might be a widget in a surrounding layout, the typical CSS media queries don't work here. Instead, the resize method checks if the width / height of the player reaches certain breakpoints, and adds appropriate classes accordingly, which in turn might be used to control layout / appearance in CSS.

Parameters:
Name Type Attributes Description
entries Array<ResizeObserverEntry> optional

The entries if using ResizeObserver, otherwise undefined.

Fires
ui/resize
Source
UI.js, line 470

getElement() → HTMLElement

Used by child components to retrieve a container element they can attach.

Returns

The element designated by the component as attachable container.

Type HTMLElement
Source
UI.js, line 501

destroy()

This method removes all events, subscriptions and DOM nodes created by this component.

Source
UI.js, line 510

Events

ui/show

This event is fired when the UI is shown.

Listeners
Controller#show
Scrubber#onUpdateStart
Title#show
Source
UI.js, line 532

ui/hide

This event is fired when the UI is hidden.

Listeners
Controller#hide
Scrubber#onUpdateStop
Popup#hidePopup
Title#hide
Source
UI.js, line 537

ui/enabled

This event is fired when the UI is enabled.

Source
UI.js, line 542

ui/disabled

This event is fired when the UI is disabled.

Source
UI.js, line 547

ui/resize

Fired when the player viewport resizes, and also once when viewport is inserted in the dom.

Parameters:
Name Type Description
size Object

New size of the player viewport.

Parameters:
Name Type Description
width number

New width of the player viewport.

height number

New height of the player viewport.

Listeners
Controller#resize
Quality#resize
Thumbnails#resize
Title#resize
VisualizerBar#resize
VisualizerFrequency#resize
VisualizerTime#resize
Source
UI.js, line 552