Deep links
A link like https://example.com/article#ml-t=42,52 can open the page with the player scrolled into view, sitting at 0:42, with 0:42 to 0:52 highlighted on the scrubber and playback pausing when it reaches 0:52. It is opt-in: only a player with deep-link (deepLink in Vue) listens.
This is the link @munsonlabs/splice writes into every clip it makes, so a viewer can go from a clip back to the full video at the same moment. The player does not depend on splice: the URL is the whole contract.
<VideoPlayer src="/video/interview.mp4" deep-link />
<ml-video-player src="/video/interview.mp4" deep-link></ml-video-player>
The link
One form, in the hash:
https://example.com/article#ml-t=42,52
https://example.com/article#ml-t=42,52&ml-player=interview
| Part | Meaning |
|---|---|
ml-t=42,52 | The range, in seconds. ml-t=42 seeks without an end; ml-t=1:02,1:10.5 is clock time too |
ml-player=<id> | Optional. Names the one player the link is for, by its deep-link="<id>" |
The keys are namespaced so they never clash with the page's own parameters, and they live in the hash rather than the query so servers, caches and crawlers see one URL per page whatever moment it points at. Hash parts are &-separated, so a single-page app's own hash route can come first: #/article/7&ml-t=42,52. A plain #t= or any ?ml-t= query is not read.
Several players on a page
A link without an id goes to the first deep-link player that asks for it; the others ignore it. To aim at a particular one, give it an id and put that id in the link:
<ml-video-player src="/video/trailer.mp4" deep-link="trailer"></ml-video-player>
<ml-video-player src="/video/interview.mp4" deep-link="interview"></ml-video-player>
<!-- https://example.com/article#ml-t=42,52&ml-player=interview -->
A player with an id still answers a link without one, if it is the first to claim it. Splice writes the id for you: give the clip's origin a player and its links carry &ml-player=<id>.
What happens
- The player scrolls to the middle of the viewport (instantly under
prefers-reduced-motion). - Once the duration is known, it seeks to the start. It does not start playing: browsers would block unmuted autoplay anyway, and the viewer chose to follow a link, not to have sound start.
- The range becomes the player's clip range, as if
setClipRange()had been called: published asclipRangeon the handle and drawn on the scrubber in--ml-video-range-color(the accent colour by default). The scrubber'saria-valuetextmentions it too. - At the end of the range,
deepLinkEnddecides (it is the clip range'sendoption):
deep-link-end | Behaviour |
|---|---|
pause (default) | Pauses once. Pressing play carries on past the end |
loop | Jumps back to the start, until the viewer seeks more than a second outside it |
continue | Plays on; the range stays highlighted |
A later hashchange (an in-page link to #ml-t=…) is treated as a new link. The remembered playback position is not restored over a deep link.
Reading the link yourself
parseDeepLink(location) is exported, for a page that wants to do something else with the moment (show a banner, pick a playlist item):
import { parseDeepLink } from '@munsonlabs/video-player'
parseDeepLink(location) // { start: 42, end: 52, target: null } or null