Skip to main content

Player API Reference

The canonical player surface — methods, properties, and events — for a player returned by requestPlayer or createPlayer.

This page describes the player object itself: the PlayerAPI interface that requestPlayer and createPlayer return in @video/video-client-core. It does not cover creating a player or wiring it into a page — see View a Stream for setup and Customize your Player for building controls on top of this surface. The manifest event and polling cadence live on Player Events & Liveness.

Every method on the player is asynchronous and returns a Promise<void> that resolves when the change has been applied.

Playback control​

MethodSignatureBehavior
playplay(): Promise<void>Begins playback. Resolves once playback has started, or once the player has settled a refused attempt — see Refused playback.
pausepause(): Promise<void>Pauses playback.
mutemute(): Promise<void>Mutes audio output.
unmuteunmute(): Promise<void>Restores audio output. Also leaves the "forced" mute state — call it from a user gesture such as a click handler.
setVolumesetVolume(value: number): Promise<void>Sets the volume. value is a number from 0 to 1, not a percentage; setVolume(0.5) is half volume.
setAutoPlaysetAutoPlay(value: boolean): Promise<void>Turns autoplay on or off.
setPostersetPoster(value: string | "last-frame" | null): Promise<void>Sets the poster to a URL, to the last decoded video frame, or clears it.
setLoopsetLoop(enabled: boolean): Promise<void>Loops VOD content when it reaches the end. Only meaningful for VOD.
seekseek(position: number): Promise<void>Seeks VOD content to position seconds. Throws if position is outside [0, duration] or the duration is not yet known. For live streams use enableDvr instead.
enableDvrenableDvr(position: number): Promise<void>Enters DVR mode at position seconds from the start of the buffered window.
disableDvrdisableDvr(): Promise<void>Leaves DVR mode and returns to the live edge.
stopstop(): Promise<void>Stops playback and releases the current source.
resetreset(options?: PlayerOptionsIn): Promise<void>Resets the player, optionally with replacement options. Clears lastError.
[Symbol.asyncDispose]await using player = …Tears down drivers and releases every resource. Equivalent to stop() followed by disposal.

Playback state​

Each property is a read-only getter. Most have a matching event in the canonical event map.

PropertyTypeMeaning
pausedbooleanPlayback is currently paused.
mutedboolean | "forced"true when muted, false when not, and "forced" when the browser's autoplay policy imposed the mute — see Forced mute.
volumenumberCurrent volume from 0 to 1.
readybooleanThe player is ready to begin playing video.
modestringCurrent playback mode, typically "live", "dvr", or "vod".
positionnumberCurrent playback position in seconds.
durationnumberDuration of the source in seconds. NaN for live streams.
loopbooleanVOD looping is on.
posterstring | nullURL of the current poster, or null.
blurredbooleanThe stream is blurred. Used for content protection and privacy features.
hasAudio / hasVideobooleanThe current source is delivering an audio or video track. Reported by the WebRTC driver and when playing a call participant, where a paused track counts as absent; other drivers do not populate them. See Audio-Only Streams.
formatstring | nullIdentifier of the current driver's format, or null when unknown.
manifestUrlstring | nullURL of the loaded manifest, or null for non-manifest sources.
srcObjectMediaStream | nullThe media stream backing playback, or null.
callCallAPI | nullThe active WebRTC call when the WebRTC driver is in use, otherwise null.
sourceMetaRecord<string, unknown>Metadata extracted from the current source.
lastErrorError | nullThe most recent error the error event reported, kept even if no listener was attached at the time. Survives driver failover and manifest recovery, so pair it with playing or ready to tell a stale error from a live one. Cleared only by reset().

Forced mute​

muted has three values, not two. "forced" means the browser refused to start unmuted playback and the player muted itself to get video on screen; the viewer did not ask for the mute. The player accepts unmute() from this state and returns to unmuted, but the browser policy that caused the forced mute still applies, so call unmute() from a user gesture — a tap-to-unmute control — rather than programmatically on load. The muted event carries the same distinction: its payload is true for an ordinary mute and "forced" for a policy-imposed one.

Refused playback​

A browser can refuse play() — autoplay policy, low-power mode, or a background tab. The player handles a refusal in two stages and does not throw for a refusal it can recover from:

  1. If an unmuted play() is rejected, the player mutes itself and retries. If the muted retry succeeds, playback starts and muted reads "forced".
  2. If the muted retry is also rejected (typically low-power mode), the player turns autoplay off and play() resolves without starting playback.

There is no dedicated refusal event. A muted event with payload "forced" tells you the unmuted attempt was refused and the muted retry succeeded; a play() that resolves while paused is still true tells you both attempts were refused. During a driver's automatic startup, a refusal that ends in forced mute still counts as a running driver, so it does not trigger driver failover.

Quality​

MemberTypeMeaning
qualitiesstring[]The quality identifiers the current source offers, for example ["240p", "720p"]. These are the values setPreferredQuality accepts.
preferredQualitystring | nullThe identifier you asked for, or null while automatic selection is active.
setPreferredQuality(name)(name: string) => Promise<void>Requests a quality by identifier. name must come from qualities; the driver may still downgrade if that rendition becomes unavailable.

The qualities and preferredQuality events fire when either value changes. The identifiers are the rendition names the source publishes, not a fixed vocabulary of quality tiers.

Rendition switching​

Whether setPreferredQuality interrupts playback depends on the active driver:

  • The WebRTC driver switches renditions without pausing.
  • Every other driver pauses playback, applies the new quality, and resumes if the player was playing. For VOD and recorded content the player also seeks back to the position it was at before the switch.

Treat a quality switch as something that can pause and resume playback, and let your controls follow the paused and playing events rather than assuming the transition is invisible.

To choose which drivers a player may use, and in what order, see Player Drivers.

Attaching to a video element​

MethodSignatureBehavior
attachToattachTo(host: unknown, force?: boolean): Promise<void>Attaches the player to an existing <video> element. Emits attached.
detachdetach(force?: boolean): Promise<void>Detaches from the current element. With force, pauses and stops the driver first. Emits detached.
attachedboolean (getter)A video element is currently attached.

Pass the element reference itself to attachTo, not an id or a selector string. The player operates on the reference you hand it and never re-queries the document, so a <video> inside a shadow root works the same way as one in the light DOM.

Calling attachTo with the element the player is already attached to is a no-op. Calling it with a different element while attached does nothing unless force is true, in which case the player detaches from the old element first and then attaches to the new one.

Drivers​

MemberTypeMeaning
driversstring[]Identifiers of the drivers configured for this player, in the order they are tried.
nextDriver()() => Promise<void>Switches to the next driver in the list.
switchDriver(driver)(driver: string) => Promise<void>Switches to a specific driver by identifier.

The player emits noDrivers when every configured driver has been exhausted for the current media. The error event, by contrast, is informational: a driver reporting a failure does not by itself stop playback, and failover continues independently.

Fullscreen​

MemberTypeMeaning
fullscreenboolean (getter)The player is in fullscreen mode.
enterFullscreen() / exitFullscreen()() => Promise<void>Enter or leave fullscreen.
fullScreenHandlers{ enter?: () => Promise<void>; exit?: () => Promise<void> }Optional replacements for the default DOM requestFullscreen and exitFullscreen flow.

Captions​

MemberTypeMeaning
captionsEnabledboolean (getter)Captions are enabled for display.
captionTracksstring[] (getter)Available caption track ids.
activeCaptionTrackstring | null (getter)The selected track, or null.
activeCaptionCuesCaptionCue[] (getter)Cues active at the current position. Empty when captions are off.
setCaptionsEnabled(enabled)(enabled: boolean) => Promise<void>Shows or hides captions.
setActiveCaptionTrack(trackId)(trackId: string | null) => Promise<void>Selects a track. Throws if trackId is not in captionTracks.

A CaptionCue carries id, startTime, endTime, and text (all required) plus an optional speaker parsed from WebVTT voice tags.

Events​

The player is a typed event emitter: player.on(name, handler) subscribes and player.off(name, handler) unsubscribes. Two event maps exist, and it matters which one you read from.

  • The canonical map, PlayerAPIEvents, is the current surface and the one this page documents.
  • The compat map, PlayerEvents, is the legacy surface. Every player still emits its events, but each is deprecated. It is not a second kind of player.

Canonical events​

EventPayloadFires when
pausedvoidPlayback entered a paused state.
playingvoidPlayback started or resumed.
canplayvoidThe player has enough data to begin playback.
readybooleanThe player entered or left the ready state.
dvrvoidDVR mode was activated.
mutedtrue | "forced"Audio was muted, by you or by the browser's autoplay policy.
unmutedvoidAudio was unmuted.
volumenumberVolume changed. Payload is the new level from 0 to 1.
posterstring | nullThe poster image changed.
blurredbooleanThe blur state changed.
attachedvoidThe player attached to a video element.
detachedvoidThe player detached from its video element.
formatstring | nullThe active format changed.
hasAudiobooleanAudio track availability changed.
hasVideobooleanVideo track availability changed.
qualitiesstring[]The set of available quality identifiers changed.
preferredQualitystring | nullThe preferred quality changed.
driversstring[]The configured driver list changed.
noDriversvoidNo configured driver can play the current media.
errorErrorA playback error was reported. Informational, not terminal; the same error is stored on lastError.
durationnumberThe media duration was reported, in seconds.
durationchangenumberThe media duration changed, in seconds.
positionnumberThe playback position advanced, in seconds.
sourceMetaRecord<string, unknown>Source metadata changed.
sourceRotationnumber | nullThe rotation reported by the manifest changed.
fullscreenbooleanFullscreen state changed.
videoFirstPlayvoidThe video element produced its first play event.
cueCaptionCue[]The active caption cues changed. Payload is the cues active for the current track.

Compat events​

The compat map contains every canonical event above except the eight listed in the next section, plus these legacy names. Prefer the canonical name wherever one exists.

Compat eventPayloadCanonical equivalent
localVideoPausedbooleanpaused / playing
localAudioMutedbooleanmuted / unmuted
localAudioVolumenumbervolume
forcedMutebooleanmuted with payload "forced"
hostElementAttached{ el: VideoElement }attached
timeupdate, progressvoidposition
driverstringnone — the active driver id changed
driverFailoverbooleannone — the player failed over to a backup driver
restartDriver{ timeout: number }none
implementationvoidnone
disposedvoidnone — the player was disposed
manifest{ state, code?, formats }none — manifest players only; see Player Events & Liveness
info{ code: string }none
playerAccessDenied{ message: string }none
peerAtCapacitybooleannone
consumerAudioEnabled, consumerVideoEnabledbooleannone (WebRTC)
noConsumerAudioAndVideobooleannone (WebRTC)
videoCodecUnreceivable{ unreceivable: …[]; negotiated: …[] }none (WebRTC)
lowLatencybooleannone (WebRTC)
joinedCall{ call: CallAPI }none (WebRTC)
callEndedvoidnone (WebRTC)
currentPlayerPlayerAPI | nullnone
isConnecting, isConnectedbooleannone (WebRTC signaling)
websocketReconnectvoidnone (WebRTC signaling)

Canonical events the compat map omits​

Eight canonical events have no entry in the compat map. If your listener types are derived from PlayerEvents, these names will not type-check, and code written against the compat surface never sees them:

canplay, cue, duration, fullscreen, position, ready, sourceMeta, sourceRotation

Subscribe to them through the canonical PlayerAPI type.

The manifest event​

Players created from a manifest URL also emit manifest on every poll of the manifest document, with state set to online, offline, or forbidden. The payload shape, the polling intervals, and how to read liveness from it are documented once, on Player Events & Liveness; this page does not repeat them.

Rendering​

The SDK renders no player chrome of its own. Attaching a player to a <video> element puts frames on screen and nothing else: every play, pause, volume, and quality control shown in the guides is authored by the integrator against the methods and events on this page. View a Stream shows both the React components and a vanilla JavaScript control set built this way, and Customize your Player walks through building your own.