Register a resolver. When anyone opens a matching URL or file the
player calls resolve; signal aborts when the open is cancelled or
replaced. One scheme + host pair, and one extension, has one resolver
(conflict otherwise). A rejected resolve fails the open with the
error's message.
Opening a https://video.example.com/… address plays the page's video.
add returns at once and registers in the background (ready reports
the answer); from then on the player calls resolve for every matching
open, and the error a rejected resolve carries is what the user sees.
plugin.resolvers.add({
id: "example",
schemes: ["https"],
hosts: ["video.example.com"], // exact host names
async resolve(url, signal) {
const response = await fetch(url, { signal });
if (!response.ok) throw new Error(`the page answered ${response.status}`);
const page = (await response.json()) as { title: string; stream: string };
return { kind: "media", originalUrl: url, title: page.title, primary: { url: page.stream } };
},
});
plugin.resolvers: turn web page URLs into playable streams, or local files into streams this plugin generates.Example: Play pages of a video site
Opening a
https://video.example.com/…page plays its video. When the user opens a URL whose scheme and host this resolver declares, the player asks the plugin first;resolvereturns the stream's address, andsignalaborts the lookup when the open is replaced or closed.Remarks
A resolver turns something the player cannot play by itself into something it can: a web page address into stream URLs (WebResolverOptions), or a local file of a format the plugin understands into a stream the plugin generates (FileResolverOptions). The player asks the resolver whenever anyone opens a matching address or file (the Open dialog, the playlist, another plugin), so the plugin does not intercept opens itself.
See
Control playback
Since
1.0.0