Features

Clip ranges

Hold playback to a stretch of the video with setClipRange, highlighted on the scrubber, pausing, looping or playing on at its end.

A clip range is a stretch of the video the player highlights on its scrubber and holds playback to: at its end it pauses once, loops back to its start, or plays on. Deep links set one from the URL; setClipRange() on the handle sets one from your code. @munsonlabs/splice's editor loops its preview this way.

<script setup lang="ts">
import { ref } from 'vue'
import { VideoPlayer, type PlayerHandle } from '@munsonlabs/video-player'

const player = ref<PlayerHandle>()

function loopChorus() {
  player.value?.setClipRange({ start: 42, end: 52 }, { end: 'loop' })
  player.value?.seek(42)
  void player.value?.play()
}
</script>

<template>
  <VideoPlayer ref="player" src="/video/interview.mp4" />
  <button @click="loopChorus">Loop the chorus</button>
  <button @click="player?.setClipRange(null)">Stop looping</button>
</template>

setClipRange(range, options?)

ArgumentTypeDescription
range{ start: number; end: number | null } or nullSeconds. end: null only highlights from start on; null clears the range
options.end'pause' | 'loop' | 'continue'What happens at the end. Defaults to 'pause'
endBehaviour
pause (default)Pauses once. Pressing play carries on past the end
loopJumps back to the start, until the viewer seeks more than a second outside it, which clears the range
continuePlays on; the range stays highlighted

Setting a range does not seek or play: the playhead stays where it is, and the end behaviour starts once it is inside the range. Seek to start yourself when that is where you want playback to be. The range is on the handle as clipRange ({ start, end } | null), so a custom HUD can show it too, and the Scrubber control highlights it. Calling it again replaces the range; a deep link that arrives later replaces it as well. The remembered playback position is not restored over a range.

The end is frame-accurate on native sources. For an MP4, HLS or DASH source the player checks the playhead on every presented frame while it plays inside the range (requestVideoFrameCallback on the <video>, or requestAnimationFrame where an engine has none), so a loop jumps back, or a pause stops, within about a frame of the end: measured on a 30fps clip, a loop's last frame lands 2-35ms past the end in WebKit and Chromium, where timeupdate alone overshot by 170-200ms. The frame callbacks run only while playing inside a range with an end, and stop on pause, at the end of the media, when the range is cleared and on unmount. timeupdate still checks as well, which is all an embed (YouTube, Vimeo, Dailymotion) has, so there the end is noticed up to a quarter of a second late; it also covers a hidden tab, where browsers stop frame callbacks. A range that runs to the end of the video loops from the ended event. Deep links are clip ranges, so they are frame-accurate too.

Why a method and not a prop

A range is something the player can let go of by itself (a loop releases it when the viewer seeks away), like the quality the viewer picks with setQuality(), so it is state the player owns, set through the handle. A clipRange prop would also shadow the exposed clipRange state on the custom element, where props are DOM properties: the same reason the handle says currentVolume and currentPlaybackRate.

munsonlabs · MIT licensed · © 2026