Skip to content

backend

TypeScript
player.backend(): IVideoBackend

Returns the active IVideoBackend instance, constructing it on first call. The backend wraps the <video> element and the hls.js instance. Most consumers do not need to call this directly, as the player’s transport and track methods cover the common cases.

Low-level use cases that require direct backend access:

  • Injecting MediaKeys for DRM (the DrmPlugin does this)
  • Rerouting audio output device via setSinkId()
  • Capturing a MediaStream for recording
TypeScript
const backend = player.backend();
await backend.setSinkId(deviceId);

videoElement

TypeScript
player.videoElement: HTMLVideoElement | undefined

The raw <video> element. undefined until the first backend() call. Prefer player.backend().mediaElement() for consistency; videoElement is a convenience shortcut on the player class.

IVideoBackend interface

TypeScript
import type { IVideoBackend } from '@nomercy-entertainment/nomercy-video-player';

Every backend implements this contract. All methods follow the player’s overloaded-function convention: read by calling with no arguments, write by calling with an argument.

Lifecycle

MethodSignatureDescription
load(url: string, opts?) => Promise<void>Load a media URL. Starts HLS attachment if the URL matches .m3u8
unload() => voidClears the source. Fires emptied on the element
dispose() => voidFull teardown: destroys the hls.js instance and detaches the element

Transport

MethodSignatureDescription
play() => Promise<void>Begin playback
pause() => voidPause playback
stop() => voidStop playback and reset position to 0; backend state becomes paused (idle requires unload)

Time and position

MethodSignatureDescription
currentTime()() => numberCurrent playback position in seconds
currentTime(seconds)(seconds: number) => voidSeek to position seconds in seconds
duration()() => numberTotal duration in seconds
buffered()() => numberEnd of the largest buffered range in seconds
bufferedRanges()() => TimeRangesFull TimeRanges object from the <video> element
seekable()() => TimeRangesSeekable range
playbackRate()() => numberCurrent playback rate
playbackRate(rate)(rate: number) => voidSet playback rate

Volume

MethodSignatureDescription
volume()() => numberCurrent volume level (0–1)
volume(level)(level: number) => voidSet volume level
mute()() => voidMute audio
unmute()() => voidUnmute audio

Video-specific

MethodSignatureDescription
videoWidth()() => numberNatural video width in pixels
videoHeight()() => numberNatural video height in pixels
audioTracks()() => AudioTrack[]Available audio renditions
setAudioTrack(idx)(idx: number) => voidActivate audio track at index
subtitleTracks()() => SubtitleTrack[]Available subtitle tracks
setSubtitleTrack(idx)(idx: number | null) => voidActivate or clear subtitle track
qualityLevels()() => QualityLevel[]Available HLS quality levels
qualityLevels({ includeUnsupported: true })() => QualityLevel[]All levels including unsupported codecs
setQuality(idx)(idx: number | 'auto') => voidPin quality or return to ABR
currentLevel()() => numberLevel index currently rendering (-1 if unknown)
state()() => BackendStateCurrent lifecycle state

Advanced

MethodSignatureDescription
mediaElement()() => HTMLVideoElementThe raw <video> element
captureStream()() => MediaStreamMediaStream for recording or processing
setSinkId(id)(id: string) => Promise<void>Route audio output to a device
getSinkId()() => stringCurrently active output device ID
mediaKeys()() => MediaKeys | undefinedActive EME MediaKeys (DRM)
setMediaKeys(keys)(keys: MediaKeys) => Promise<void>Bind MediaKeys to the element
outputProtectionState()() => 'unrestricted' | 'restricted' | 'unsupported'HDCP protection status
pauseLoader()() => voidPause HLS fragment loading (backpressure)
resumeLoader()() => voidResume HLS fragment loading
loaderState()() => 'running' | 'paused'Current loader state

BackendState

ValueDescription
'idle'No source loaded
'loading'Source is loading
'ready'Source is loaded and ready
'playing'Media is playing
'paused'Media is paused
'error'A fatal backend error occurred

Custom backend

Pass a backendFactory in VideoPlayerConfig to swap the default Html5VideoBackend:

TypeScript
import type { VideoBackendFactory } from '@nomercy-entertainment/nomercy-video-player';
import { MyNativeBackend } from './MyNativeBackend';

const factory: VideoBackendFactory = (kind, config) => {
return new MyNativeBackend(config);
};

player.setup({ backendFactory: factory, playlist: [...] });

See Video Backend adapter for the full adapter guide.

See also