Skip to content

Transport

nomercy-video-player doesn’t reimplement transport. Every method below is nomercy-player-core’s Transport Contract: a cancellable before* dispatch, then a call into the video backend. Video adds nothing to the surface here, only a real <video> element for it to drive.

Play, pause, stop

play(), pause(), stop(), and togglePlayback() all return a Promise<void> that resolves once the backend call settles. next() / previous() move the queue cursor and load, restart() seeks to 0 and resumes.

TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player';

const player = nmplayer('player');

await player.play();
await player.pause();
await player.togglePlayback(); // flips based on the current playState()
await player.stop();
await player.next();
await player.previous();
await player.restart();

Every one of these accepts an ActionOptions bag { source, silent } (next() and previous() take the wider LoadOptions, which extends it). source defaults to 'user' and gets stamped onto the emitted event, so a Connect plugin syncing playback across devices can tell its own remote-triggered play() apart from a real click.

Seeking through time()

time() reads the current position in seconds; time(seconds) seeks to a new one, there is no separate seek() method. Position is reported by two different events for two different reasons: ordinary playback ticks the time event (per frame) and the throttled progress event, while a deliberate jump fires the cancellable beforeSeekseekseeked cycle. That is the split the web platform draws between timeupdate and seeking/seeked, the tick versus the jump:

TypeScript
const currentTime = player.time(); // seconds
await player.time(120); // jump to 2:00

rewind(seconds?) and forward(seconds?) compute a relative target from the current position and run it through the same beforeSeekseekseeked cycle; both default to a 5-second step when called with no argument. seekByPercentage(pct) seeks to a position expressed as 0100 percent of duration(), the calculation a progress bar’s click handler would otherwise have to do by hand:

TypeScript
await player.rewind(10); // -10s
await player.forward(30); // +30s
player.seekByPercentage(50); // jump to the halfway point

Guard first

Every transport method calls the kit’s _assertReady() guard before doing anything else. Calling play() before setup() resolves, or after dispose(), throws a typed StateError instead of silently reaching into missing state — the same contract Core: Transport Contract documents in full, including the preventDefault() / delay() shape of the before* event.

Next steps

  • Volume: volume(), mute()/unmute(), and the volume gain state a slider or mute icon reads.