@vestra-player/sdk 1.6.19 → 1.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/commands.js +19 -18
  3. package/dist/docs-tree.json.gz +0 -0
  4. package/dist/i18n-tools.js +7 -2
  5. package/dist/plugin/runtime.d.ts +1 -0
  6. package/dist/plugin/runtime.js +3 -0
  7. package/dist/plugin/types/base.d.ts +1097 -0
  8. package/dist/plugin/types/base.js +1 -0
  9. package/dist/plugin/types/commands.d.ts +1189 -0
  10. package/dist/plugin/types/commands.js +1 -0
  11. package/dist/plugin/types/packages.d.ts +661 -0
  12. package/dist/plugin/types/packages.js +1 -0
  13. package/dist/plugin/types/playback.d.ts +1654 -0
  14. package/dist/plugin/types/playback.js +1 -0
  15. package/dist/plugin/types/processing.d.ts +974 -0
  16. package/dist/plugin/types/processing.js +1 -0
  17. package/dist/plugin/types/services.d.ts +1132 -0
  18. package/dist/plugin/types/services.js +1 -0
  19. package/dist/plugin/types/snapshots.d.ts +491 -0
  20. package/dist/plugin/types/snapshots.js +1 -0
  21. package/dist/plugin/types/sources.d.ts +302 -0
  22. package/dist/plugin/types/sources.js +1 -0
  23. package/dist/plugin/types/subtitles.d.ts +327 -0
  24. package/dist/plugin/types/subtitles.js +1 -0
  25. package/dist/plugin/types/ui-content.d.ts +692 -0
  26. package/dist/plugin/types/ui-content.js +1 -0
  27. package/dist/plugin/types/ui-layout.d.ts +1079 -0
  28. package/dist/plugin/types/ui-layout.js +1 -0
  29. package/dist/plugin/types/ui-locale.d.ts +490 -0
  30. package/dist/plugin/types/ui-locale.js +1 -0
  31. package/dist/plugin/types/ui-shell.d.ts +1072 -0
  32. package/dist/plugin/types/ui-shell.js +1 -0
  33. package/dist/plugin/types.d.ts +18 -11072
  34. package/llms.txt +1 -1
  35. package/package.json +1 -1
@@ -0,0 +1,1654 @@
1
+ import type { Host } from "./commands.ts";
2
+ import type { PluginInfo } from "./packages.ts";
3
+ import type { MediaCapture } from "./snapshots.ts";
4
+ import type { FileResolverOptions, Resolver } from "./sources.ts";
5
+ import type { View } from "./ui-content.ts";
6
+ import type { Disposable, PluginError } from "./base.ts";
7
+ import type { Bindable } from "./commands.ts";
8
+ import type { Text } from "./ui-locale.ts";
9
+ /**
10
+ * What a timeline mark stands for; readers choose colours by it.
11
+ *
12
+ * @since 1.0.0
13
+ * @category Playback
14
+ */
15
+ export type MarkKind = "chapter" | "bookmark" | "marker";
16
+ /**
17
+ * One mark on the seek bar.
18
+ *
19
+ * @since 1.0.0
20
+ * @category Playback
21
+ */
22
+ export interface TimelineMark {
23
+ /** Seconds from the start. */
24
+ readonly time: number;
25
+ /** The mark's kind. */
26
+ readonly kind: MarkKind;
27
+ /** Label, `null` without one. */
28
+ readonly title: string | null;
29
+ /** The manifest id of the plugin that published it. */
30
+ readonly plugin: string;
31
+ }
32
+ /**
33
+ * How a timeline range is drawn; readers choose colours by it.
34
+ *
35
+ * - `"selection"`: a span the user picked to act on, such as a clip to
36
+ * export. The player's seek bar draws it in the accent colour.
37
+ * - `"region"`: a part of the media the plugin describes, such as an intro
38
+ * or a chapter's span. Drawn dimmer, under selections.
39
+ *
40
+ * @since 1.6.9
41
+ * @category Playback
42
+ */
43
+ export type RangeStyle = "selection" | "region";
44
+ /**
45
+ * One range on the seek bar (player 0.7.6).
46
+ *
47
+ * @since 1.6.9
48
+ * @category Playback
49
+ */
50
+ export interface TimelineRange {
51
+ /** Seconds from the start. */
52
+ readonly start: number;
53
+ /** Seconds from the start, after `start`. */
54
+ readonly end: number;
55
+ /** How it is drawn. */
56
+ readonly style: RangeStyle;
57
+ /** Label, `null` without one. */
58
+ readonly title: string | null;
59
+ /** The manifest id of the plugin that published it. */
60
+ readonly plugin: string;
61
+ }
62
+ /**
63
+ * This plugin's own marks; disposing it removes them.
64
+ *
65
+ * @remarks
66
+ * This plugin's marks on the seek bar, from {@link Timeline.layer}. `set`
67
+ * replaces the whole layer and never throws: the newest write wins, and a
68
+ * refused one is reported to `onError`. Disposing the layer, its scope or
69
+ * stopping the plugin removes the marks.
70
+ *
71
+ * @capability timeline.marks
72
+ *
73
+ * @example Clear the plugin's marks
74
+ * The plugin's marks disappear from the seek bar while it keeps its
75
+ * layer for later. An empty list clears the layer; other plugins' marks
76
+ * stay.
77
+ * ```ts
78
+ * plugin.timeline.layer().set([]);
79
+ * ```
80
+ *
81
+ * @since 1.0.0
82
+ * @category Playback
83
+ */
84
+ export interface TimelineLayer extends Disposable {
85
+ /**
86
+ * Replace the layer (last write wins; `[]` clears it). At most 1000 marks,
87
+ * titles ≤ 100 characters, times within the media. Failures go to `onError`;
88
+ * with `ifCurrent`, a write for another source is dropped silently.
89
+ * A title is data (a chapter's or bookmark's own name), or a {@link Text}
90
+ * the player translates (`text("Chapter {}", [n])`, SDK 1.5.11); other
91
+ * plugins read the shown string.
92
+ *
93
+ * @example Show the file's bookmarks on the timeline
94
+ * Bookmark marks appear on the seek bar at their times, titled with the
95
+ * user's notes. `set` replaces this plugin's whole layer; with `ifCurrent`
96
+ * the player drops the write if another file opened since `seen` was
97
+ * read, so bookmarks of the previous file never land on the new one.
98
+ * ```ts
99
+ * declare const bookmarks: { time: number; note: string }[];
100
+ * // ---cut---
101
+ * const layer = plugin.timeline.layer();
102
+ * const seen = plugin.player.state; // the file the bookmarks belong to
103
+ * layer.set(
104
+ * bookmarks.map((b) => ({ time: b.time, kind: "bookmark", title: b.note })),
105
+ * { ifCurrent: seen },
106
+ * );
107
+ * ```
108
+ *
109
+ * @capability timeline.marks
110
+ * @since 1.0.0
111
+ */
112
+ set(marks: {
113
+ time: number;
114
+ kind: MarkKind;
115
+ title?: string | Text;
116
+ }[], options?: {
117
+ ifCurrent?: PlayerState;
118
+ }): void;
119
+ /**
120
+ * Replace the layer's ranges (last write wins; `[]` clears them), spans of
121
+ * the media drawn on the seek bar (player 0.7.6). The marks and the ranges
122
+ * of a layer are replaced on their own: `set` keeps the ranges and
123
+ * `setRanges` keeps the marks. Disposing the layer, its scope or stopping
124
+ * the plugin removes both, and a new source clears every layer.
125
+ *
126
+ * At most 100 ranges (`TIMELINE_LIMITS.ranges`), `0 ≤ start < end`, `end`
127
+ * within the media while its duration is known, titles ≤ 100 characters.
128
+ * Ranges may overlap. Failures go to `onError`; with `ifCurrent`, a
129
+ * write for another source is dropped silently. A title is data or a
130
+ * {@link Text} the player translates, as in `set`.
131
+ *
132
+ * Players before 0.7.6 build `plugin` from an SDK without `setRanges`, so
133
+ * the call throws a `TypeError` there: declare
134
+ * `"minPlayerVersion": "0.7.6"`.
135
+ *
136
+ * @example Show the clip range on the seek bar while a panel is open
137
+ * The span the user picked shows on the seek bar in the accent colour
138
+ * while the plugin's tab is showing, and goes when it is not. Two point
139
+ * marks would show the ends but not the span between them.
140
+ * ```ts
141
+ * declare const panel: Panel;
142
+ * declare const clip: { start: number; end: number };
143
+ * // ---cut---
144
+ * const layer = plugin.timeline.layer();
145
+ * // Only while the tab is on screen; [] takes the range away.
146
+ * const show = () =>
147
+ * layer.setRanges(
148
+ * panel.state?.effective
149
+ * ? [{ start: clip.start, end: clip.end, style: "selection", title: "Clip" }]
150
+ * : [],
151
+ * { ifCurrent: plugin.player.state },
152
+ * );
153
+ * panel.onChange(show);
154
+ * ```
155
+ *
156
+ * @capability timeline.marks
157
+ * @since 1.6.9
158
+ */
159
+ setRanges(ranges: {
160
+ start: number;
161
+ end: number;
162
+ style: RangeStyle;
163
+ title?: string | Text;
164
+ }[], options?: {
165
+ ifCurrent?: PlayerState;
166
+ }): void;
167
+ }
168
+ /**
169
+ * `plugin.timeline`: marks on the seek bar. Every plugin publishes one
170
+ * layer; the player merges them. A new source clears every layer.
171
+ *
172
+ * @remarks
173
+ * Marks on the player's seek bar: chapters, bookmarks, loop points. Each
174
+ * plugin publishes one layer with {@link Timeline.layer}; the player merges
175
+ * the layers by time and shows them. A new source clears every layer, so a
176
+ * plugin publishes again for each file. `marks` is the merged list, which
177
+ * any plugin can read.
178
+ *
179
+ * @capability `timeline.marks` to publish; `playback.read` to read;
180
+ * `events` to follow changes.
181
+ *
182
+ * @example Count the chapter marks other plugins published
183
+ * The plugin reads how many chapter marks the seek bar shows, whoever
184
+ * published them. `marks` is the merged list of every layer, sorted by
185
+ * time, with each mark's `plugin`.
186
+ * ```ts
187
+ * const chapters = plugin.timeline.marks.filter((mark) => mark.kind === "chapter");
188
+ * await plugin.osd.show("{} chapters", [chapters.length]);
189
+ * ```
190
+ *
191
+ * @since 1.0.0
192
+ * @category Playback
193
+ */
194
+ export interface Timeline {
195
+ /** Every layer merged, by time (`playback.read`). Empty on a new source. */
196
+ readonly marks: readonly TimelineMark[];
197
+ /**
198
+ * Every layer's ranges merged, by start (`playback.read`; player 0.7.6:
199
+ * on older players `ranges` does not exist and reads `undefined`). Empty
200
+ * on a new source. Kept current like `marks` (with `events`): read it in
201
+ * a {@link View.bind} function and the view follows it. `onChange` runs
202
+ * only when the marks change.
203
+ *
204
+ * @example Draw the published ranges in a seek bar of your own
205
+ * A bottom bar draws a band for every range on the seek bar, whoever
206
+ * published it, as fractions of the duration.
207
+ * ```ts
208
+ * declare const bar: View;
209
+ * // ---cut---
210
+ * bar.bind(() => {
211
+ * // Reading `ranges` here runs the binding again when they change.
212
+ * const duration = plugin.player.state.duration ?? 0;
213
+ * return {
214
+ * ranges: duration
215
+ * ? plugin.timeline.ranges.map((range) => ({
216
+ * from: range.start / duration,
217
+ * to: range.end / duration,
218
+ * selection: range.style === "selection",
219
+ * }))
220
+ * : [],
221
+ * };
222
+ * });
223
+ * ```
224
+ *
225
+ * @capability playback.read
226
+ * @since 1.6.9
227
+ */
228
+ readonly ranges: readonly TimelineRange[];
229
+ /**
230
+ * The merged list changed (needs `events`; at most every 100 ms).
231
+ *
232
+ * @capability events and playback.read
233
+ *
234
+ * @example Follow the marks as they change
235
+ * A panel lists the seek bar's marks and updates when any plugin publishes
236
+ * or a new file clears them. The listener gets the merged list, at most
237
+ * every 100 ms.
238
+ * ```ts
239
+ * plugin.timeline.onChange((marks) => {
240
+ * console.log(marks.map((mark) => `${mark.time}s ${mark.title ?? mark.kind}`));
241
+ * });
242
+ * ```
243
+ *
244
+ * @since 1.0.0
245
+ */
246
+ onChange(listener: (marks: readonly TimelineMark[]) => void): Disposable;
247
+ /**
248
+ * This plugin's layer (`timeline.marks`); a second call throws.
249
+ *
250
+ * @capability timeline.marks
251
+ *
252
+ * @example Publish this plugin's marks
253
+ * The plugin gets its one layer and puts two chapter marks on the seek
254
+ * bar. Calling `layer()` again while the first layer is not disposed
255
+ * throws; disposing the layer removes the
256
+ * marks.
257
+ * ```ts
258
+ * const layer = plugin.timeline.layer();
259
+ * layer.set([
260
+ * { time: 0, kind: "chapter", title: "Intro" },
261
+ * { time: 95, kind: "chapter", title: "Part 1" }, // seconds
262
+ * ]);
263
+ * ```
264
+ *
265
+ * @since 1.0.0
266
+ */
267
+ layer(): TimelineLayer;
268
+ }
269
+ /**
270
+ * One audio track of the current media ({@link PlayerState.audioTracks}).
271
+ *
272
+ * @since 1.0.0
273
+ * @category Playback
274
+ */
275
+ export interface AudioTrack {
276
+ /** The backend's track id; pass it to {@link Player.selectAudioTrack}. */
277
+ id: number;
278
+ /** The track is playing. */
279
+ selected: boolean;
280
+ /** True for an external track; such tracks cannot be exported. */
281
+ external: boolean;
282
+ /** False when the track is not inside the source container. */
283
+ exportable: boolean;
284
+ /** Codec name, `null` when unknown. */
285
+ codec: string | null;
286
+ /** Track title, `null` when unknown. */
287
+ title: string | null;
288
+ /** Language tag, `null` when unknown. */
289
+ language: string | null;
290
+ }
291
+ /**
292
+ * An immutable view of the player. Keep one to make a later call conditional on it.
293
+ *
294
+ * Without `events`, {@link Player.state} only updates at start and after
295
+ * this plugin's own operations.
296
+ *
297
+ * @see {@link Player.state}, [Playback state, controls and sources](../../../docs/explanation/playback.md)
298
+ * @since 1.0.0
299
+ * @category Playback
300
+ */
301
+ export interface PlayerState {
302
+ /** Changes every time a source is opened, even the same file again. */
303
+ readonly sourceId: number;
304
+ /** `stream` for a generated source ({@link Player.openStream}). */
305
+ readonly kind: "media" | "stream";
306
+ /** The source's life cycle. */
307
+ readonly phase: "empty" | "loading" | "ready" | "ended" | "error";
308
+ /**
309
+ * Path or URL; `null` when empty. A generated stream started with
310
+ * {@link Player.openStream} has the opaque `producer://<n>` (do not parse
311
+ * it); one a file resolver generates ({@link FileResolverOptions}) keeps
312
+ * the path that was opened. Tell streams apart by `kind`, not by `source`.
313
+ */
314
+ readonly source: string | null;
315
+ /** Playback is paused. */
316
+ readonly paused: boolean;
317
+ /** Seconds, `null` without media. */
318
+ readonly position: number | null;
319
+ /** Seconds, `null` when unknown (live streams). */
320
+ readonly duration: number | null;
321
+ /** Playback speed (1 = normal). */
322
+ readonly rate: number;
323
+ /** Device volume 0–200. */
324
+ readonly volume: number;
325
+ /** Device output is muted. */
326
+ readonly muted: boolean;
327
+ /** Why the last playthrough stopped. */
328
+ readonly endReason: "natural" | "stopped" | "replaced" | "unknown" | null;
329
+ /** Load failure text when `phase` is `error`. */
330
+ readonly error: string | null;
331
+ /** Which controls the current source allows. */
332
+ readonly can: {
333
+ /** {@link Player.setPaused}. */
334
+ pause: boolean;
335
+ /** {@link Player.seek} and {@link Player.scrub}. */
336
+ seek: boolean;
337
+ /** {@link Player.setRate}. */
338
+ rate: boolean;
339
+ /** {@link Player.restart}. */
340
+ restart: boolean;
341
+ /** {@link Player.close}. */
342
+ close: boolean;
343
+ /** {@link MediaCapture.capture}. */
344
+ snapshot: boolean;
345
+ /** A sequence provider exists and can go forward / back (`player.next()`). */
346
+ next: boolean;
347
+ /** A sequence provider exists and can go back (`player.previous()`). */
348
+ previous: boolean;
349
+ };
350
+ /** The media's audio tracks; `null` before they are known. */
351
+ readonly audioTracks: AudioTrack[] | null;
352
+ /**
353
+ * The A-B loop (`setLoop`) as requested; `count` null = endless. Cleared by
354
+ * a new source. The SDK always sets it (`null` = no loop); it is optional
355
+ * only so hand-written test states without it still type-check.
356
+ */
357
+ readonly loop?: {
358
+ /** Loop start, seconds. */
359
+ a: number;
360
+ /** Loop end, seconds. */
361
+ b: number;
362
+ /** Requested repetitions (not the remaining ones); `null` = endless. */
363
+ count: number | null;
364
+ } | null;
365
+ /**
366
+ * The output device `setAudioDevice` asked for and the one in use (`null`
367
+ * = system default). Always set by the SDK; optional for the same reason
368
+ * as `loop`.
369
+ */
370
+ readonly audioOutput?: {
371
+ /** The device id asked for, `null` = system default. */
372
+ requested: string | null;
373
+ /** The device in use, `null` = system default. */
374
+ active: string | null;
375
+ };
376
+ }
377
+ /**
378
+ * An audio output device (`player.audioDevices`).
379
+ *
380
+ * @since 1.0.0
381
+ * @category Playback
382
+ */
383
+ export interface AudioDevice {
384
+ /** Stable id to pass to `setAudioDevice` (e.g. `coreaudio/<UID>`). */
385
+ id: string;
386
+ /** What the system calls it. */
387
+ name: string;
388
+ }
389
+ /**
390
+ * One chapter of the current media.
391
+ *
392
+ * @since 1.0.0
393
+ * @category Playback
394
+ */
395
+ export interface Chapter {
396
+ /** Chapter title, `null` without one. */
397
+ title: string | null;
398
+ /** Seconds. */
399
+ start: number;
400
+ }
401
+ /**
402
+ * Controls act on the state you are looking at: by default `player.state`.
403
+ * If another plugin or the user changed the source in between, the call fails
404
+ * with code `stale` and nothing happens. Pass `ifCurrent` to bind the call to
405
+ * an older snapshot instead (for example the state when a drag started).
406
+ *
407
+ * The SDK refreshes `player.state` after its own operations, so a plugin's
408
+ * consecutive calls do not make each other stale. {@link Player.open} is
409
+ * unconditional unless `ifCurrent` is given.
410
+ *
411
+ * @example Play the next file only if nothing else was opened
412
+ * When the plugin's file ends, the next one starts, unless the user or
413
+ * another plugin opened something in the meantime. `onEnd` passes the
414
+ * state at the end; `open` with `ifCurrent: ended` is refused with `stale`
415
+ * when the source changed after that state, so nothing is replaced.
416
+ * ```ts
417
+ * declare const media: Media;
418
+ * declare const next: string;
419
+ * // ---cut---
420
+ * media.onEnd(async (ended) => {
421
+ * try {
422
+ * await plugin.player.open(next, { ifCurrent: ended });
423
+ * } catch (error) {
424
+ * // Someone opened another file: leave it playing.
425
+ * if ((error as PluginError).code !== "stale") throw error;
426
+ * }
427
+ * });
428
+ * ```
429
+ *
430
+ * @see [Playback state, controls and sources](../../../docs/explanation/playback.md)
431
+ * @since 1.0.0
432
+ * @category Playback
433
+ */
434
+ export interface Conditional {
435
+ /** The state the call is conditional on; default: the current `player.state`. */
436
+ ifCurrent?: PlayerState;
437
+ }
438
+ /**
439
+ * A source this plugin opened.
440
+ *
441
+ * @remarks
442
+ * A source this plugin opened with {@link Player.open}. It does not own
443
+ * the source: the user or another plugin can replace it at any time, and
444
+ * `current` then turns false. `ready` and `onEnd` follow the player state:
445
+ * with `events` they react to the player's events, without it `ready`
446
+ * polls the state every 100 ms (which needs `playback.read`). Disposing the
447
+ * scope that opened it does not close the media; call `close` for that.
448
+ *
449
+ * @capability That of {@link Player.open} (`playback.control`); `ready` and
450
+ * `onEnd` follow the state through `events` and `playback.read`.
451
+ *
452
+ * @example Open a file and say when it ends
453
+ * The file opens and plays, and the OSD says "Finished" when it reaches its
454
+ * end on its own. The handle belongs to this source: `onEnd` fires only
455
+ * for a natural end of this media, not when someone opens another file.
456
+ * ```ts
457
+ * const media = await plugin.player.open("/Movies/clip.mp4");
458
+ * media.onEnd(() => void plugin.osd.show("Finished")); // natural ends only
459
+ * ```
460
+ *
461
+ * @since 1.0.0
462
+ * @category Playback
463
+ */
464
+ export interface Media {
465
+ /** Still the player's source (a restart keeps it current). */
466
+ readonly current: boolean;
467
+ /**
468
+ * Resolves when it is playing. Rejects with code `failed` (load error),
469
+ * `replaced` (another source took over) or `ended`; with `AbortError` when
470
+ * the signal aborts, after closing the media.
471
+ *
472
+ * @capability That of {@link Player.open}; `playback.read` or `events` to
473
+ * see the state change.
474
+ * @throws `failed` (rejects) The media could not be loaded.
475
+ * @throws `replaced` (rejects) Another source took over first.
476
+ * @throws `ended` (rejects) The media already played to the end.
477
+ * @throws `aborted` (rejects) `signal` aborted (an `AbortError`); the media
478
+ * is closed.
479
+ *
480
+ * @example Wait at most ten seconds for a stream to start
481
+ * A network stream gets ten seconds to start playing; otherwise it is
482
+ * closed and the user is told. Aborting the signal makes `ready` reject
483
+ * with an `AbortError` after closing the media.
484
+ * ```ts
485
+ * const media = await plugin.player.open("https://example.com/live.m3u8");
486
+ * // The timeout's abort closes the media and rejects with an AbortError.
487
+ * try {
488
+ * await media.ready({ signal: AbortSignal.timeout(10_000) });
489
+ * } catch (error) {
490
+ * await plugin.osd.show("Not playing: {}", [(error as Error).message]);
491
+ * }
492
+ * ```
493
+ *
494
+ * @since 1.0.0
495
+ */
496
+ ready(options?: {
497
+ signal?: AbortSignal;
498
+ }): Promise<void>;
499
+ /**
500
+ * Called once each time a playthrough of this media ends naturally.
501
+ *
502
+ * @capability That of {@link Player.open}; `events` to hear the end.
503
+ *
504
+ * @example Play the next file when this one ends
505
+ * When the plugin's file ends naturally, the next one opens. The listener
506
+ * gets the state at the end; passing it as `ifCurrent` makes the next
507
+ * `open` fail with `stale` (and do nothing) if the user opened something
508
+ * else in the meantime.
509
+ * ```ts
510
+ * declare const media: Media;
511
+ * declare const next: string;
512
+ * // ---cut---
513
+ * media.onEnd((ended) =>
514
+ * plugin.player.open(next, { ifCurrent: ended }).catch((error: PluginError) => {
515
+ * if (error.code !== "stale") throw error; // the user opened something else
516
+ * }),
517
+ * );
518
+ * ```
519
+ *
520
+ * @since 1.0.0
521
+ */
522
+ onEnd(listener: (state: PlayerState) => void): Disposable;
523
+ /**
524
+ * Close it if it is still the player's source; otherwise do nothing.
525
+ *
526
+ * @capability That of {@link Player.open} (`playback.control`).
527
+ * @throws `capability` (rejects) The manifest does not declare
528
+ * `playback.control`.
529
+ *
530
+ * @example Close the preview the plugin opened
531
+ * The plugin closes the preview it opened, but leaves alone anything the
532
+ * user opened since. `close` acts only while this media is still the
533
+ * player's source and does nothing otherwise.
534
+ * ```ts
535
+ * declare const preview: Media;
536
+ * // ---cut---
537
+ * await preview.close(); // a no-op when something else is playing now
538
+ * ```
539
+ *
540
+ * @since 1.0.0
541
+ */
542
+ close(): Promise<void>;
543
+ }
544
+ /**
545
+ * A drag gesture: each seek is conditional on the previous one, latest value wins.
546
+ * Any outside change (another plugin opens a file, the user pauses) ends
547
+ * the gesture.
548
+ *
549
+ * @example Seek while the user drags a slider
550
+ * The video follows the slider while it is dragged. `scrub()` starts a
551
+ * gesture from the current state; each `seek` is conditional on the
552
+ * previous one and only the newest target is sent while one is running,
553
+ * so a fast drag does not queue seeks. A change from outside (another file,
554
+ * the user pausing) ends the gesture and later seeks resolve `false`.
555
+ * ```ts
556
+ * declare const bar: Panel;
557
+ * // ---cut---
558
+ * let scrub: Scrub | null = null;
559
+ * bar.on("dragStart", () => (scrub = plugin.player.scrub()));
560
+ * // Latest value wins: superseded targets resolve false, not an error.
561
+ * bar.on("dragMove", (seconds: number) => void scrub?.seek(seconds));
562
+ * bar.on("dragEnd", () => scrub?.end());
563
+ * ```
564
+ *
565
+ * @remarks
566
+ * A drag gesture on a seek slider. Each `seek` is conditional on the
567
+ * previous one and only the newest target is sent while a seek is
568
+ * running, so a fast drag never queues seeks. Any outside change (another
569
+ * file, the user pausing) ends the gesture: `active` turns false and later
570
+ * seeks resolve `false`.
571
+ *
572
+ * @capability playback.control
573
+ * @see [Keep a slider responsive while dragging](../../../docs/how-to/slider.md)
574
+ * @since 1.0.0
575
+ * @category Playback
576
+ */
577
+ export interface Scrub {
578
+ /**
579
+ * Seek within the gesture. Resolves `true` when this target was applied,
580
+ * `false` when a newer target superseded it or the gesture ended. Rejects
581
+ * on a host failure.
582
+ *
583
+ * `keyframes: true` (player 0.5.3, SDK 1.5.22): land on the last keyframe
584
+ * at or before `seconds` instead of decoding up to that exact frame. The
585
+ * picture appears at once on any file (tens of milliseconds instead of
586
+ * seconds on 4K video with keyframes far apart), up to one keyframe
587
+ * interval before the target; the position the player reports is the
588
+ * keyframe's. Use it when the user chose keyframe seeks (the same switch
589
+ * as {@link Player.setStepSeek}), and the exact seek otherwise. The player
590
+ * sends a repeated target of the same gesture only once while the seek is
591
+ * still running (a click is a press and a release), but an exact seek to
592
+ * the target of a keyframe seek is always sent. Omitted or `false`: exact,
593
+ * as before. Older players ignore the option and seek exactly: set
594
+ * `"minPlayerVersion": "0.5.3"` when you rely on it.
595
+ *
596
+ * @example Scrub on keyframes for a fast picture
597
+ * While dragging, the picture jumps to the nearest earlier keyframe at
598
+ * once instead of decoding up to the exact frame. With `keyframes: true`
599
+ * the player lands each target on the last keyframe at or before it; the
600
+ * plugin follows the user's keyframe-seek setting.
601
+ * ```ts
602
+ * declare const bar: Panel;
603
+ * declare const scrub: Scrub | null;
604
+ * // ---cut---
605
+ * const keyframes = true; // the plugin's own setting
606
+ * bar.on("dragMove", (seconds: number) => void scrub?.seek(seconds, { keyframes }));
607
+ * ```
608
+ *
609
+ * @capability playback.control
610
+ * @throws `capability` (rejects) The manifest does not declare
611
+ * `playback.control`.
612
+ * @throws `stale` (rejects) The source changed from outside while this
613
+ * seek was being sent (a superseded target or an ended gesture resolves
614
+ * `false` instead).
615
+ * @throws `unsupported` (rejects) The source is a generated stream.
616
+ * @throws `backend` (rejects) The player failed the seek.
617
+ * @since 1.0.0
618
+ */
619
+ seek(seconds: number, options?: {
620
+ keyframes?: boolean;
621
+ }): Promise<boolean>;
622
+ /** False once anyone else changed the source; later seeks are ignored. */
623
+ readonly active: boolean;
624
+ /**
625
+ * End the gesture; later seeks resolve `false`.
626
+ *
627
+ * @capability playback.control
628
+ *
629
+ * @example End the gesture when the user lets go
630
+ * Releasing the slider ends the gesture, so a late `dragMove` cannot move
631
+ * playback any more. After `end`, `seek` resolves `false` without doing
632
+ * anything.
633
+ * ```ts
634
+ * declare const bar: Panel;
635
+ * declare const scrub: Scrub;
636
+ * // ---cut---
637
+ * bar.on("dragEnd", () => scrub.end()); // later seeks resolve false
638
+ * ```
639
+ *
640
+ * @since 1.0.0
641
+ */
642
+ end(): void;
643
+ }
644
+ /**
645
+ * Frames a stream supplies on demand: RGBA pixels and 48 kHz stereo f32 PCM.
646
+ *
647
+ * Limits: the picture is exactly `width × height × 4` bytes and at most
648
+ * 4 MiB (1280×720 fits, 1920×1080 does not: lower the resolution, the
649
+ * player scales it). Every sample is finite and within −1…1; clamp your
650
+ * own mix. A frame that breaks a limit ends the stream with `invalid`
651
+ * (`openStream` rejects, or {@link Stream.onStop} gets the error).
652
+ *
653
+ * The SDK copies the frame once before `frame()` is called again, so you
654
+ * may reuse the same buffers for every frame.
655
+ *
656
+ * @since 1.0.0
657
+ * @category Playback
658
+ */
659
+ export interface StreamFrame {
660
+ /** `width × height × 4` bytes of RGBA, at most 4 MiB. */
661
+ video: Uint8Array;
662
+ /**
663
+ * Interleaved stereo samples at 48 kHz for this frame's duration (an even
664
+ * length, any number of frames; the SDK sends them in packets of at most
665
+ * 4800). Each sample finite, −1…1.
666
+ */
667
+ audio: Float32Array;
668
+ }
669
+ /**
670
+ * Options of {@link Player.openStream}.
671
+ *
672
+ * @see {@link Player.openStream}
673
+ * @since 1.0.0
674
+ * @category Playback
675
+ */
676
+ export interface StreamOptions {
677
+ /** Frame width in pixels. */
678
+ width: number;
679
+ /** Frame height in pixels. */
680
+ height: number;
681
+ /** Produce the next frame. Never called concurrently or while paused. */
682
+ frame(): StreamFrame;
683
+ /** Aborting stops the stream. */
684
+ signal?: AbortSignal;
685
+ }
686
+ /**
687
+ * `openStream` start-up timeouts: code `timeout` with the step that ran out
688
+ * of time, the first buffers (`prefill`) or the host's activation.
689
+ * Both limits are 10 seconds.
690
+ *
691
+ * @since 1.0.0
692
+ * @category Playback
693
+ */
694
+ export type StreamStartError = PluginError & {
695
+ /** The start-up step that timed out. */
696
+ stage: "prefill" | "activation";
697
+ };
698
+ /**
699
+ * A generated source, from {@link Player.openStream}. Disposing it stops it.
700
+ *
701
+ * @remarks
702
+ * A source whose frames this plugin generates, from
703
+ * {@link Player.openStream}. The SDK pulls frames on the audio clock over
704
+ * a local connection and handles prefill, activation and pausing; the plugin
705
+ * only supplies `frame()`. A stream ends when the plugin stops it, when
706
+ * another source replaces it or the user closes it (`onStop` with `null`),
707
+ * or when it fails (`onStop` with the error).
708
+ *
709
+ * @capability producer.av and playback.control
710
+ *
711
+ * @example Stop the stream from a menu item
712
+ * A menu item ends the plugin's generated stream and closes it as the
713
+ * player's source. `stop` closes the source first and then the frame
714
+ * connection, so the user never sees a playback error; `onStop` is not
715
+ * called for the plugin's own stop.
716
+ * ```ts
717
+ * declare const stream: Stream;
718
+ * // ---cut---
719
+ * // Enabled while the stream produces frames.
720
+ * plugin.commands.add({
721
+ * id: "stop-generator",
722
+ * path: ["@playback", "Stop generator"],
723
+ * enabled: () => stream.running,
724
+ * run: () => stream.stop(),
725
+ * });
726
+ * ```
727
+ *
728
+ * @see {@link Player.openStream}
729
+ * @since 1.0.0
730
+ * @category Playback
731
+ */
732
+ export interface Stream extends Disposable {
733
+ /** The stream is producing frames. */
734
+ readonly running: boolean;
735
+ /**
736
+ * The stream stopped for a reason outside this plugin: `error` is null when
737
+ * another source replaced it or the user closed it, otherwise the failure
738
+ * (`stream` with the player's text, `invalid` for a bad frame, …). Not
739
+ * called when the plugin itself stops it (`stop()`, `dispose()`,
740
+ * deactivation): the promise of `stop()` is that notification.
741
+ *
742
+ * The player retires a stream's producer as soon as it is replaced or
743
+ * closed; the SDK reads the player's state to tell that from a failure
744
+ * (before 1.5.7 a replaced or closed stream could get `unavailable`
745
+ * "producer absent"). Without `playback.read` a failure the SDK has not
746
+ * seen yet is reported as null.
747
+ *
748
+ * @capability producer.av
749
+ *
750
+ * @example Tell the user why the stream stopped
751
+ * The OSD explains a failure, and nothing is said when the user simply
752
+ * opened another file. The listener runs only for stops from outside the
753
+ * plugin: `null` for a replacement or the user's close, an error (such as
754
+ * `stream` with the player's text) for a failure.
755
+ * ```ts
756
+ * declare const stream: Stream;
757
+ * // ---cut---
758
+ * stream.onStop((error) => {
759
+ * if (error) void plugin.osd.show("Generator stopped: {}", [error.message]);
760
+ * });
761
+ * ```
762
+ *
763
+ * @since 1.0.0
764
+ */
765
+ onStop(listener: (error: PluginError | null) => void): Disposable;
766
+ /**
767
+ * Stop producing and close the stream if it is still the player's source.
768
+ * The source closes first, then the frame connection, then the producer,
769
+ * so stopping never shows as a playback failure. `dispose()` and
770
+ * deactivation do the same.
771
+ *
772
+ * @capability producer.av and playback.control
773
+ * @throws Whatever code closing the player's source failed with (the
774
+ * frame connection and the producer are released either way). A
775
+ * stream that is no longer the source just resolves.
776
+ *
777
+ * @example Stop the stream when the plugin's window closes
778
+ * Closing the generator window stops the stream it feeds. `stop` closes
779
+ * the player's source if it is still this stream and then the frame
780
+ * connection; it resolves once both are closed.
781
+ * ```ts
782
+ * declare const stream: Stream;
783
+ * declare const generatorWindow: Window;
784
+ * // ---cut---
785
+ * generatorWindow.onClose(() => stream.stop());
786
+ * ```
787
+ *
788
+ * @since 1.0.0
789
+ */
790
+ stop(): Promise<void>;
791
+ }
792
+ /**
793
+ * The plugin that owns "next / previous" (a playlist).
794
+ *
795
+ * @see {@link Player.provideSequence}
796
+ * @since 1.0.0
797
+ * @category Playback
798
+ */
799
+ export interface SequenceProvider {
800
+ /** Go to the next item (called in the provider's scope). */
801
+ next(): unknown;
802
+ /** Go to the previous item. */
803
+ previous(): unknown;
804
+ /** Whether there is a next item; shown as `state.can.next`. */
805
+ canNext: Bindable<boolean>;
806
+ /** Whether there is a previous item; shown as `state.can.previous`. */
807
+ canPrevious: Bindable<boolean>;
808
+ }
809
+ /**
810
+ * What {@link Player.stats} reports. Every field is the backend's own value
811
+ * (libmpv properties), `null` when it has none; nothing is converted.
812
+ *
813
+ * @see {@link Player.stats}
814
+ * @since 1.0.0
815
+ * @category Playback
816
+ */
817
+ export interface PlaybackStats {
818
+ /**
819
+ * The rendering path: "libmpv · GPU 渲染(OpenGL)" (GPU on macOS, the
820
+ * default there), "libmpv · GPU 渲染(Direct3D)" (GPU on Windows, when
821
+ * turned on; version 0.5.14 and later) or "libmpv · 软件渲染" (software: Windows by
822
+ * default, Linux, headless, fallback). The strings are the player's
823
+ * display text in the interface language (shown here in Chinese).
824
+ */
825
+ backend: string;
826
+ /** The playback session number. */
827
+ session: number;
828
+ /**
829
+ * Frames the video renderer produced. Not all of them reach the screen: a
830
+ * busy window shows only the newest one, so compare
831
+ * {@link PlaybackStats.presentedFps | presentedFps}.
832
+ */
833
+ framesShown: number;
834
+ /** Frames dropped by the backend (mpv), `null` when unknown. */
835
+ framesDropped: number | null;
836
+ /**
837
+ * New video frames the player window showed per second over the last
838
+ * second, measured by the player itself: draws of the main window that put
839
+ * a new picture on screen. Lower than `video.fps` when frames are lost
840
+ * after decoding and rendering (the window could not keep up with the
841
+ * source, or the display refreshes slower); `0` while paused. `null` when
842
+ * the player cannot measure it (no window, the first second, players
843
+ * before 0.5.1).
844
+ *
845
+ * @player 0.5.1
846
+ * @since 1.5.15
847
+ */
848
+ presentedFps: number | null;
849
+ /** Every field is the backend's own value, `null` when it has none. */
850
+ video: {
851
+ /** Codec name. */
852
+ codec: string | null;
853
+ /** Coded width. */
854
+ width: number | null;
855
+ /** Coded height. */
856
+ height: number | null;
857
+ /** Frames per second (after a `frameBlend` node: the output rate). */
858
+ fps: number | null;
859
+ /** Short decoder name, e.g. "h264". */
860
+ decoder: string | null;
861
+ /** e.g. "yuv420p". */
862
+ pixelFormat: string | null;
863
+ /** Colour matrix, e.g. "bt.709". */
864
+ colorspace: string | null;
865
+ /** Size after aspect correction and filters. */
866
+ displayWidth: number | null;
867
+ /** Size after aspect correction and filters. */
868
+ displayHeight: number | null;
869
+ /** Measured display refresh; only with display-synced output (usually null). */
870
+ displayFps: number | null;
871
+ /** Bits per second, updated per keyframe. */
872
+ bitrate: number | null;
873
+ /** Hardware decoder in use, e.g. "videotoolbox", "d3d11va-copy"; "no" = software decoding. */
874
+ hwdec: string | null;
875
+ /**
876
+ * How the video is decoded, from `hwdec`: `"hardware"` (the method is in
877
+ * `hwdec`) or `"software"`; `null` before a decoder runs.
878
+ *
879
+ * @since 1.5.15 (with older players the SDK derives it from `hwdec`)
880
+ */
881
+ decoding: "hardware" | "software" | null;
882
+ /** Transfer characteristic as mpv names it, e.g. "bt.1886", "pq", "hlg". */
883
+ transfer: string | null;
884
+ } | null;
885
+ /** `null` without audio. */
886
+ audio: {
887
+ /** Codec name. */
888
+ codec: string | null;
889
+ /** Hz. */
890
+ sampleRate: number | null;
891
+ /** Channel count. */
892
+ channels: number | null;
893
+ /** Short decoder name, e.g. "aac". */
894
+ decoder: string | null;
895
+ /** Sample format, e.g. "floatp". */
896
+ format: string | null;
897
+ /** Readable layout, e.g. "stereo", "5.1(side)". */
898
+ channelLayout: string | null;
899
+ /** Bits per second. */
900
+ bitrate: number | null;
901
+ } | null;
902
+ /** Last audio/video difference in milliseconds (signed). */
903
+ avSyncMs: number | null;
904
+ /** Seconds of media buffered ahead by the demuxer. */
905
+ cacheSeconds: number | null;
906
+ }
907
+ /**
908
+ * `plugin.player`: playback state and controls.
909
+ *
910
+ * Capabilities: reading (`state` at start, `refresh`, `stats`, `chapters`,
911
+ * `audioDevices`) needs `playback.read`; live updates and `onChange` need
912
+ * `events`; every control needs `playback.control`; `openStream` needs
913
+ * `producer.av` as well as `playback.control`.
914
+ *
915
+ * Controls are conditional (see {@link Conditional}): they fail with
916
+ * `stale` and do nothing when the source changed since the state you saw.
917
+ *
918
+ * @example Open a file and wait until it plays
919
+ * The file opens and the plugin learns whether it started playing within
920
+ * ten seconds. `open` resolves once the player accepted the load and
921
+ * returns a `Media` handle; `ready` waits for playback and rejects with
922
+ * `failed` (load error), `replaced` (another source took over) or an
923
+ * `AbortError` when the timeout fires, which closes the media.
924
+ * ```ts
925
+ * const media = await plugin.player.open("/Movies/clip.mp4"); // load accepted
926
+ * try {
927
+ * await media.ready({ signal: AbortSignal.timeout(10_000) });
928
+ * } catch (error) {
929
+ * void plugin.osd.show("Cannot play: {}", [(error as Error).message]);
930
+ * }
931
+ * ```
932
+ *
933
+ * @remarks
934
+ * `plugin.player` is the player's one source: what is open, its phase and
935
+ * position, and the controls. `state` is a snapshot the SDK keeps current
936
+ * from the player's events (with `events`) and refreshes after this
937
+ * plugin's own calls; `onChange` runs after it changed. Every control is
938
+ * conditional: it acts on the state the plugin last saw and fails with
939
+ * `stale` when the source changed meanwhile: another file, a close, or any
940
+ * pause, seek or speed change by the user or another plugin (see
941
+ * {@link Conditional}). The player keeps the source when a plugin stops;
942
+ * only the plugin's own handles (a stream, its sequence provider, its
943
+ * output device) are withdrawn.
944
+ *
945
+ * @capability `playback.read` to read; `playback.control` to control;
946
+ * `events` to follow changes made elsewhere; `producer.av` for
947
+ * {@link Player.openStream}.
948
+ *
949
+ * @see [Playback state, controls and sources](../../../docs/explanation/playback.md), [Control playback](../../../docs/how-to/control-playback.md)
950
+ * @since 1.0.0
951
+ * @category Playback
952
+ */
953
+ export interface Player {
954
+ /** Latest state; always newer than anything delivered before. */
955
+ readonly state: PlayerState;
956
+ /**
957
+ * The state changed (needs `events` for outside changes).
958
+ *
959
+ * @capability events (for changes made elsewhere; without it the listener
960
+ * runs only after this plugin's own calls)
961
+ *
962
+ * @example Show the position while it plays
963
+ * The OSD block shows the position, updated as playback moves. The SDK
964
+ * updates `player.state` from the player's events and then calls the
965
+ * listener with the new snapshot; the handler only reads it.
966
+ * ```ts
967
+ * const info = plugin.osd.panel();
968
+ * plugin.player.onChange((state) => {
969
+ * // `position` is null while nothing is open.
970
+ * info.set(state.position === null ? null : "{} s", [state.position?.toFixed(0) ?? ""]);
971
+ * });
972
+ * ```
973
+ *
974
+ * @since 1.0.0
975
+ */
976
+ onChange(listener: (state: PlayerState) => void): Disposable;
977
+ /**
978
+ * Read the state from the player now (`playback.read`).
979
+ *
980
+ * @capability playback.read
981
+ * @throws `capability` (rejects) The manifest does not declare
982
+ * `playback.read`.
983
+ *
984
+ * @example Read the state before deciding
985
+ * A command reads the newest state from the player before acting, even
986
+ * without `events`. `refresh` asks the player and resolves with the new
987
+ * snapshot; `player.state` holds it afterwards.
988
+ * ```ts
989
+ * const state = await plugin.player.refresh();
990
+ * if (state.phase === "ready") await plugin.osd.show("{} s left", [((state.duration ?? 0) - (state.position ?? 0)).toFixed(0)]);
991
+ * ```
992
+ *
993
+ * @since 1.0.0
994
+ */
995
+ refresh(): Promise<PlayerState>;
996
+ /**
997
+ * True if nothing changed the source since `state` was observed.
998
+ *
999
+ * @capability None.
1000
+ *
1001
+ * @example Drop a result that arrives after the file changed
1002
+ * A slow lookup for the current file is shown only if that file is still
1003
+ * open. `isCurrent` compares the snapshot taken before the work with the
1004
+ * SDK's newest state; it is false once the source changed in any way:
1005
+ * another file, a close, or a pause, seek or speed change by anyone.
1006
+ * ```ts
1007
+ * declare function lookUpTitle(path: string): Promise<string>;
1008
+ * // ---cut---
1009
+ * const seen = plugin.player.state;
1010
+ * const title = await lookUpTitle(seen.source ?? "");
1011
+ * if (plugin.player.isCurrent(seen)) await plugin.osd.show("{}", [title]); // still the same file
1012
+ * ```
1013
+ *
1014
+ * @since 1.0.0
1015
+ */
1016
+ isCurrent(state: PlayerState): boolean;
1017
+ /**
1018
+ * Open a path or URL, replacing the current source (unless `ifCurrent` no
1019
+ * longer holds). Resolves when the host accepted the load.
1020
+ *
1021
+ * It does not wait for playback: use {@link Media.ready}. `paused` opens
1022
+ * it paused; aborting `signal` closes it. URLs matching a registered
1023
+ * {@link Resolver} are resolved first, and so are local files of an
1024
+ * extension a file resolver claims (the source is then a stream that
1025
+ * plugin generates; `paused` reaches it).
1026
+ *
1027
+ * @capability playback.control
1028
+ * @throws `stale` (rejects) `ifCurrent` no longer holds; nothing was opened.
1029
+ * @throws `replaced` (rejects) Accepted, then another source took over
1030
+ * before it finished (for example while a URL was still being resolved).
1031
+ * @throws `invalid` (rejects) An empty `source`.
1032
+ * @throws `aborted` (rejects) `signal` aborted (an `AbortError`); the
1033
+ * source is closed if it was opened.
1034
+ * @throws `busy` (rejects) The address needs a resolver plugin and the
1035
+ * player is already resolving 32 addresses.
1036
+ * @throws `backend` (rejects) A resolver plugin handled the address or
1037
+ * file and failed (its message), or the resolution was cancelled or
1038
+ * expired.
1039
+ * @throws `unsupported` (rejects) The player refused what a resolver
1040
+ * returned (for example split streams with different headers).
1041
+ * @throws `unavailable` (rejects) The stream a file resolver prepared was
1042
+ * not ready to play.
1043
+ * @throws `capability` (rejects) The manifest does not declare
1044
+ * `playback.control`.
1045
+ *
1046
+ * @example Open a file paused
1047
+ * The file opens at its start without playing. `open` resolves once the
1048
+ * player accepted the load and returns a {@link Media} handle for that
1049
+ * source; `ready` then waits until it can play (here: until it is loaded
1050
+ * and paused).
1051
+ * ```ts
1052
+ * const media = await plugin.player.open("/Movies/clip.mp4", { paused: true });
1053
+ * await media.ready(); // rejects `failed` when the file cannot be loaded
1054
+ * ```
1055
+ *
1056
+ * @since 1.0.0
1057
+ */
1058
+ open(source: string, options?: {
1059
+ paused?: boolean;
1060
+ signal?: AbortSignal;
1061
+ } & Conditional): Promise<Media>;
1062
+ /**
1063
+ * Start a source whose frames this plugin generates. Needs `producer.av`
1064
+ * and `playback.control` (the stream becomes the player's source, like
1065
+ * {@link Player.open}).
1066
+ *
1067
+ * The SDK calls `frame()` on the audio clock and handles prefill,
1068
+ * activation, pausing and acknowledgement. Frames travel over a local
1069
+ * connection the SDK sets up: a Unix socket on macOS and Linux, loopback
1070
+ * TCP with a token on Windows. Rejects with a {@link StreamStartError}
1071
+ * (`timeout`), `stream`, `device`, or `replaced` when another source
1072
+ * replaced it (or it was closed) before it ran.
1073
+ *
1074
+ * @example Play pictures the plugin draws itself
1075
+ * The player shows a 320×240 picture the plugin renders, with silence as
1076
+ * its sound, as the current source. The SDK pulls frames on the audio
1077
+ * clock: each `frame()` returns one picture (RGBA bytes) and the audio
1078
+ * that plays with it, here 1/60 s, so the picture runs at 60 frames a
1079
+ * second; `frame()` may run several times back to back to refill the
1080
+ * lead. `onStop` tells the plugin when and why the stream ended.
1081
+ * ```ts
1082
+ * declare function render(into: Uint8Array): Uint8Array;
1083
+ * // ---cut---
1084
+ * const frame = new Uint8Array(320 * 240 * 4); // RGBA, reused per frame
1085
+ * const silence = new Float32Array(2 * 800); // 1/60 s of stereo at 48 kHz
1086
+ * const stream = await plugin.player.openStream({
1087
+ * width: 320,
1088
+ * height: 240,
1089
+ * frame: () => ({ video: render(frame), audio: silence }),
1090
+ * });
1091
+ * // `error` is null when the stream stopped normally.
1092
+ * stream.onStop((error) => error && plugin.osd.show(error.message));
1093
+ * ```
1094
+ *
1095
+ * @capability producer.av and playback.control
1096
+ * @throws `timeout` (rejects) A {@link StreamStartError}: the stream did not
1097
+ * start in time.
1098
+ * @throws `stream` (rejects) The player failed to start the stream.
1099
+ * @throws `device` (rejects) The audio device was not ready.
1100
+ * @throws `replaced` (rejects) Another source replaced it, or it was closed,
1101
+ * before it ran.
1102
+ * @throws `invalid` (rejects) Bad options (a size or a frame function).
1103
+ * @throws `aborted` (rejects) `signal` aborted, or the scope was disposed,
1104
+ * while the stream was starting (an `AbortError`).
1105
+ * @since 1.0.0
1106
+ */
1107
+ openStream(options: StreamOptions): Promise<Stream>;
1108
+ /**
1109
+ * Pause or resume.
1110
+ *
1111
+ * @capability playback.control
1112
+ * @throws `stale` (rejects) The source changed since the state the call is
1113
+ * based on (another file, a close, or any pause, seek
1114
+ * or speed change by the user or another plugin); nothing was done.
1115
+ * @throws `invalid` (rejects) Nothing is open.
1116
+ * @throws `busy` (rejects) A generated stream is still handling a previous
1117
+ * control.
1118
+ * @throws `capability` (rejects) The manifest does not declare
1119
+ * `playback.control`.
1120
+ *
1121
+ * @example Pause, but only the file the user was watching
1122
+ * A "pause on lock" helper pauses the current file and does nothing when
1123
+ * another file was opened in between. The call is conditional on
1124
+ * `player.state` by default; `stale` means the source changed and the
1125
+ * pause was not applied, which is the intended outcome here.
1126
+ * ```ts
1127
+ * try {
1128
+ * await plugin.player.setPaused(true);
1129
+ * } catch (error) {
1130
+ * if ((error as PluginError).code !== "stale") throw error; // another file now
1131
+ * }
1132
+ * ```
1133
+ *
1134
+ * @since 1.0.0
1135
+ */
1136
+ setPaused(paused: boolean, options?: Conditional): Promise<void>;
1137
+ /**
1138
+ * Jump to `seconds`.
1139
+ *
1140
+ * @capability playback.control
1141
+ * @throws `stale` (rejects) The source changed since the state the call is
1142
+ * based on (another file, a close, or any pause, seek
1143
+ * or speed change by the user or another plugin); nothing was done.
1144
+ * @throws `invalid` (rejects) Nothing is open, or `seconds` is negative or
1145
+ * not finite.
1146
+ * @throws `unsupported` (rejects) The source is a generated stream, which
1147
+ * cannot seek.
1148
+ * @throws `busy` (rejects) A generated stream is still handling a previous
1149
+ * control.
1150
+ * @throws `capability` (rejects) The manifest does not declare
1151
+ * `playback.control`.
1152
+ *
1153
+ * @example Jump back ten seconds
1154
+ * Playback jumps ten seconds back, never before the start. The target is
1155
+ * computed from the snapshot the call is conditional on, so if the user
1156
+ * opened another file meanwhile the seek fails with `stale` instead of
1157
+ * landing in the wrong file.
1158
+ * ```ts
1159
+ * const { position } = plugin.player.state;
1160
+ * if (position !== null && plugin.player.state.can.seek)
1161
+ * await plugin.player.seek(Math.max(0, position - 10)); // seconds
1162
+ * ```
1163
+ *
1164
+ * @since 1.0.0
1165
+ */
1166
+ seek(seconds: number, options?: Conditional): Promise<void>;
1167
+ /**
1168
+ * Set the playback speed.
1169
+ *
1170
+ * @capability playback.control
1171
+ * @throws `stale` (rejects) The source changed since the state the call is
1172
+ * based on (another file, a close, or any pause, seek
1173
+ * or speed change by the user or another plugin); nothing was done.
1174
+ * @throws `invalid` (rejects) Nothing is open, or `rate` is outside
1175
+ * 0.05–10.
1176
+ * @throws `unsupported` (rejects) The source is a generated stream, which
1177
+ * cannot change speed.
1178
+ * @throws `busy` (rejects) A generated stream is still handling a previous
1179
+ * control.
1180
+ * @throws `capability` (rejects) The manifest does not declare
1181
+ * `playback.control`.
1182
+ *
1183
+ * @example Play at one and a half times the speed
1184
+ * Playback speeds up to 1.5×, with the speed on the OSD. `setRate` sets
1185
+ * the speed directly (the player's own keys step it by 0.1 within
1186
+ * 0.25–4); `state.can.rate` is false for sources that cannot change speed.
1187
+ * ```ts
1188
+ * if (plugin.player.state.can.rate) {
1189
+ * await plugin.player.setRate(1.5);
1190
+ * await plugin.osd.show("Speed {}×", [1.5]);
1191
+ * }
1192
+ * ```
1193
+ *
1194
+ * @since 1.0.0
1195
+ */
1196
+ setRate(rate: number, options?: Conditional): Promise<void>;
1197
+ /**
1198
+ * Play from the start (the "replay" after the end).
1199
+ *
1200
+ * @capability playback.control
1201
+ * @throws `stale` (rejects) The source changed since the state the call is
1202
+ * based on (another file, a close, or any pause, seek
1203
+ * or speed change by the user or another plugin); nothing was done.
1204
+ * @throws `invalid` (rejects) Nothing is open.
1205
+ * @throws `unsupported` (rejects) The source is a generated stream, which
1206
+ * cannot restart.
1207
+ * @throws `capability` (rejects) The manifest does not declare
1208
+ * `playback.control`.
1209
+ *
1210
+ * @example Replay a file after it ended
1211
+ * A Replay button starts the file again from its start once it has ended.
1212
+ * `restart` plays the current source from the beginning and keeps it the
1213
+ * same source, so a {@link Media} handle stays current.
1214
+ * ```ts
1215
+ * if (plugin.player.state.phase === "ended") await plugin.player.restart();
1216
+ * ```
1217
+ *
1218
+ * @since 1.0.0
1219
+ */
1220
+ restart(options?: Conditional): Promise<void>;
1221
+ /**
1222
+ * Close the current source.
1223
+ *
1224
+ * @capability playback.control
1225
+ * @throws `stale` (rejects) The source changed since the state the call is
1226
+ * based on (another file, a close, or any pause, seek
1227
+ * or speed change by the user or another plugin); nothing was done.
1228
+ * @throws `capability` (rejects) The manifest does not declare
1229
+ * `playback.control`.
1230
+ *
1231
+ * @example Close the file when the sleep timer runs out
1232
+ * After 30 minutes the open file is closed, unless the user opened another
1233
+ * one meanwhile. The snapshot taken when the timer started is passed as
1234
+ * `ifCurrent`, so the close applies only to that source; `stale` means it
1235
+ * was replaced.
1236
+ * ```ts
1237
+ * const seen = plugin.player.state;
1238
+ * setTimeout(() => {
1239
+ * // Only the source that was open when the timer started.
1240
+ * plugin.player.close({ ifCurrent: seen }).catch((error: PluginError) => {
1241
+ * if (error.code !== "stale") plugin.osd.show("Could not close: {}", [error.code]);
1242
+ * });
1243
+ * }, 30 * 60 * 1000);
1244
+ * ```
1245
+ *
1246
+ * @since 1.0.0
1247
+ */
1248
+ close(options?: Conditional): Promise<void>;
1249
+ /**
1250
+ * Start a drag gesture from the current state.
1251
+ *
1252
+ * @capability playback.control
1253
+ *
1254
+ * @example Start a gesture when the user grabs the slider
1255
+ * A drag on the plugin's seek slider becomes one gesture whose seeks never
1256
+ * pile up. `scrub()` captures the current state; the gesture's seeks are
1257
+ * conditional on it and on each other, and it ends on its own when
1258
+ * someone else changes the source.
1259
+ * ```ts
1260
+ * declare const bar: Panel;
1261
+ * // ---cut---
1262
+ * let scrub: Scrub | null = null;
1263
+ * bar.on("dragStart", () => (scrub = plugin.player.scrub()));
1264
+ * bar.on("dragEnd", () => scrub?.end());
1265
+ * ```
1266
+ *
1267
+ * @see [Keep a slider responsive while dragging](../../../docs/how-to/slider.md)
1268
+ * @since 1.0.0
1269
+ */
1270
+ scrub(): Scrub;
1271
+ /**
1272
+ * Device output; last write wins and volume is applied before mute.
1273
+ * Resolves `true` when this request was applied, `false` if superseded.
1274
+ * `volume` is 0–200.
1275
+ *
1276
+ * @capability playback.control
1277
+ * @throws `invalid` (rejects) `volume` outside 0–200, or `muted` not a
1278
+ * boolean.
1279
+ * @throws `capability` (rejects) The manifest does not declare
1280
+ * `playback.control`.
1281
+ *
1282
+ * @example Duck the volume during an announcement
1283
+ * The volume drops to 30 while the plugin's announcement plays, then
1284
+ * returns. Writes are "latest wins": the promise resolves `true` when this
1285
+ * write was applied and `false` when a newer one replaced it first, which
1286
+ * is not an error.
1287
+ * ```ts
1288
+ * const before = plugin.player.state.volume; // 0–200
1289
+ * await plugin.player.setOutput({ volume: 30 });
1290
+ * // … the announcement …
1291
+ * await plugin.player.setOutput({ volume: before });
1292
+ * ```
1293
+ *
1294
+ * @since 1.0.0
1295
+ */
1296
+ setOutput(output: {
1297
+ volume?: number;
1298
+ muted?: boolean;
1299
+ }): Promise<boolean>;
1300
+ /**
1301
+ * Become the sequence provider, first come first served: while another
1302
+ * plugin holds it (the built-in playlist registers at activation), this
1303
+ * one is refused with `conflict` (`sequence-taken`). That does not fail
1304
+ * activation: the player shows a warning ({@link PluginInfo.warnings});
1305
+ * a refusal after activation goes to the scope's `onError`. Dispose to
1306
+ * stop.
1307
+ *
1308
+ * @example Drive the player's Next and Previous from a playlist
1309
+ * The player's Next and Previous items and keys play the plugin's list.
1310
+ * The player calls `next` and `previous` when the user asks; `canNext`
1311
+ * and `canPrevious` are evaluated again after every handler the SDK runs
1312
+ * (and after a player state change if they read a changed field), and while they return false the player disables its items ("No next
1313
+ * item").
1314
+ * ```ts
1315
+ * declare const items: string[];
1316
+ * let index = 0;
1317
+ * // ---cut---
1318
+ * const playAt = async (at: number) => {
1319
+ * index = at;
1320
+ * await plugin.player.open(items[at]!);
1321
+ * };
1322
+ * // Called by the player's Next / Previous items, keys and buttons.
1323
+ * plugin.player.provideSequence({
1324
+ * next: () => playAt(index + 1),
1325
+ * previous: () => playAt(index - 1),
1326
+ * canNext: () => index + 1 < items.length,
1327
+ * canPrevious: () => index > 0,
1328
+ * });
1329
+ * ```
1330
+ *
1331
+ * @capability playback.control
1332
+ * @since 1.0.0
1333
+ */
1334
+ provideSequence(provider: SequenceProvider): Disposable;
1335
+ /**
1336
+ * Ask the provider to go forward / back. Rejects `unavailable` when it cannot.
1337
+ *
1338
+ * @capability playback.control
1339
+ * @throws `unavailable` (rejects) There is no sequence provider, or it has
1340
+ * no next item.
1341
+ * @throws `capability` (rejects) The manifest does not declare
1342
+ * `playback.control`.
1343
+ *
1344
+ * @example Skip to the next item from a plugin button
1345
+ * The plugin's own Next button plays the next item of whichever plugin
1346
+ * provides the sequence (the playlist, usually). `next` asks the
1347
+ * provider, the same as the player's Next key; `unavailable` means there
1348
+ * is no next item, which the button treats as the end of the list.
1349
+ * ```ts
1350
+ * try {
1351
+ * await plugin.player.next(); // as the player's Next key does
1352
+ * } catch (error) {
1353
+ * if ((error as PluginError).code !== "unavailable") throw error;
1354
+ * await plugin.osd.show("End of the list");
1355
+ * }
1356
+ * ```
1357
+ *
1358
+ * @since 1.0.0
1359
+ */
1360
+ next(): Promise<void>;
1361
+ /**
1362
+ * Ask the provider to go back. Rejects `unavailable` when it cannot.
1363
+ *
1364
+ * @capability playback.control
1365
+ * @throws `unavailable` (rejects) There is no sequence provider, or it has
1366
+ * no previous item.
1367
+ * @throws `capability` (rejects) The manifest does not declare
1368
+ * `playback.control`.
1369
+ *
1370
+ * @example Go back to the previous item
1371
+ * The plugin's Previous button asks the sequence provider for the item
1372
+ * before the current one, like the player's PageUp. It is disabled while
1373
+ * `state.can.previous` is false, which the provider's `canPrevious`
1374
+ * decides.
1375
+ * ```ts
1376
+ * plugin.commands.add({
1377
+ * id: "previous",
1378
+ * title: "Previous item",
1379
+ * // The provider's `canPrevious`, as the player reports it.
1380
+ * enabled: () => plugin.player.state.can.previous,
1381
+ * run: () => plugin.player.previous(),
1382
+ * });
1383
+ * ```
1384
+ *
1385
+ * @since 1.0.0
1386
+ */
1387
+ previous(): Promise<void>;
1388
+ /**
1389
+ * Codec, size, frame counts and backend of the current playback.
1390
+ * `playback.read`; `video` and `audio` are `null` without a source.
1391
+ *
1392
+ * @capability playback.read
1393
+ * @throws `capability` (rejects) The manifest does not declare
1394
+ * `playback.read`.
1395
+ *
1396
+ * @example Show the video codec and size
1397
+ * The OSD shows something like "h264 1920×1080". `stats` asks the player
1398
+ * for the backend's own values at that moment; `video` is `null` without
1399
+ * a video stream (nothing open, an audio file).
1400
+ * ```ts
1401
+ * const { video } = await plugin.player.stats();
1402
+ * if (video) await plugin.osd.show("{} {}×{}", [video.codec ?? "?", video.width ?? 0, video.height ?? 0]);
1403
+ * ```
1404
+ *
1405
+ * @since 1.0.0
1406
+ */
1407
+ stats(): Promise<PlaybackStats>;
1408
+ /**
1409
+ * Add an external audio file (absolute local path) to the current media and,
1410
+ * unless `select: false`, select it. Resolves with the new track (`external`,
1411
+ * not exportable). It stays until the source changes. Rejects `invalid` for a
1412
+ * bad path, `unavailable` without ready media, `backend` when it cannot load.
1413
+ *
1414
+ * @capability playback.control
1415
+ * @throws `invalid` (rejects) Not an absolute path to a file.
1416
+ * @throws `unavailable` (rejects) No ready media.
1417
+ * @throws `backend` (rejects) The player could not load the file.
1418
+ * @throws `stale` (rejects) `ifCurrent` no longer holds.
1419
+ * @throws `capability` (rejects) The manifest does not declare
1420
+ * `playback.control`.
1421
+ *
1422
+ * @example Add a dubbed audio file and switch to it
1423
+ * A separate audio file plays with the film instead of its own sound.
1424
+ * `addAudioTrack` attaches the file to the current media and selects it;
1425
+ * the track stays until another source opens.
1426
+ * ```ts
1427
+ * declare const dubPath: string;
1428
+ * // ---cut---
1429
+ * const track = await plugin.player.addAudioTrack(dubPath); // selected too
1430
+ * await plugin.osd.show("Audio: {}", [track.title ?? dubPath]);
1431
+ * ```
1432
+ *
1433
+ * @since 1.0.0
1434
+ */
1435
+ addAudioTrack(path: string, options?: {
1436
+ select?: boolean;
1437
+ } & Conditional): Promise<AudioTrack>;
1438
+ /**
1439
+ * Select one of `state.audioTracks` by id; `invalid` for an unknown id.
1440
+ *
1441
+ * @capability playback.control
1442
+ * @throws `invalid` (rejects) No track with this id.
1443
+ * @throws `unavailable` (rejects) No ready media.
1444
+ * @throws `stale` (rejects) The source changed since the state the call is
1445
+ * based on (another file, a close, or any pause, seek
1446
+ * or speed change by the user or another plugin).
1447
+ * @throws `capability` (rejects) The manifest does not declare
1448
+ * `playback.control`.
1449
+ *
1450
+ * @example Switch to the next audio track
1451
+ * Each press of the plugin's key moves to the next audio track of the
1452
+ * file. The tracks and the selected one are in `state.audioTracks`;
1453
+ * `selectAudioTrack` resolves with the new state.
1454
+ * ```ts
1455
+ * const audioTracks = plugin.player.state.audioTracks ?? []; // null: not known yet
1456
+ * const at = audioTracks.findIndex((track) => track.selected);
1457
+ * const next = audioTracks[(at + 1) % audioTracks.length];
1458
+ * if (next) await plugin.player.selectAudioTrack(next.id);
1459
+ * ```
1460
+ *
1461
+ * @since 1.0.0
1462
+ */
1463
+ selectAudioTrack(id: number, options?: Conditional): Promise<PlayerState>;
1464
+ /**
1465
+ * One frame or to the next / previous keyframe (pauses for frames). Rejects
1466
+ * `unsupported` without moving video (audio only, cover art, a generated
1467
+ * stream) or when backwards needs a seekable source.
1468
+ *
1469
+ * Resolves once the new position is in effect, so `player.state.position`
1470
+ * is current afterwards. One step at a time: a second call while one is
1471
+ * in flight rejects `busy`.
1472
+ *
1473
+ * @capability playback.control
1474
+ * @throws `unsupported` (rejects) Nothing playable to step through (no
1475
+ * moving video: audio only, cover art, a generated stream), a backward
1476
+ * frame step on a source that cannot seek, or a keyframe step in either
1477
+ * direction on a source that cannot seek.
1478
+ * @throws `busy` (rejects) A step is still in flight.
1479
+ * @throws `stale` (rejects) The source changed since the state the call is
1480
+ * based on (another file, a close, or any pause, seek
1481
+ * or speed change by the user or another plugin).
1482
+ * @throws `capability` (rejects) The manifest does not declare
1483
+ * `playback.control`.
1484
+ *
1485
+ * @example Step one frame forward for a close look
1486
+ * The picture advances by one frame and playback pauses. `step` resolves
1487
+ * once the new position is in effect, so `state.position` is current
1488
+ * afterwards; a second step while one is running rejects with `busy`.
1489
+ * ```ts
1490
+ * await plugin.player.step("frame", "forward");
1491
+ * await plugin.osd.show("{} s", [plugin.player.state.position?.toFixed(3) ?? "?"]);
1492
+ * ```
1493
+ *
1494
+ * @since 1.0.0
1495
+ */
1496
+ step(unit: "frame" | "keyframe", direction: "backward" | "forward", options?: Conditional): Promise<void>;
1497
+ /**
1498
+ * The core's first-tier relative seek (`seek-backward` / `seek-forward`,
1499
+ * ← / →): 0.1–3600 seconds in tenths, default 5. The newest call of any
1500
+ * plugin wins; it reverts when that plugin stops.
1501
+ *
1502
+ * `keyframes: true` (player 0.5.1, SDK 1.5.19): the step seeks
1503
+ * (`seek-backward` / `seek-forward`, including {@link Host.run} with
1504
+ * `seconds` and the picture-in-picture skips) land on a keyframe instead
1505
+ * of the exact time: forward on the first keyframe at or after position +
1506
+ * step, backward on the last at or before position − step, and they
1507
+ * always move. Presses during a seek add up and continue from where it
1508
+ * landed; the on-screen text shows the landed time. Sources without moving
1509
+ * video seek exactly. {@link Player.seek}, chapters, loops and
1510
+ * {@link Player.step} are unaffected, and so is a scrub unless it asks for
1511
+ * keyframes itself ({@link Scrub.seek} with `keyframes: true`, SDK 1.5.22).
1512
+ * Omitted or `false`: exact seeks, as before. `seconds` and `keyframes`
1513
+ * are written as a pair: the newest call sets both.
1514
+ *
1515
+ * Older players ignore `keyframes`: set `"minPlayerVersion": "0.5.1"` in
1516
+ * the manifest when you rely on it.
1517
+ *
1518
+ * @capability playback.control
1519
+ * @throws `invalid` (rejects) `seconds` outside 0.1–3600 or not in tenths,
1520
+ * or `keyframes` not a boolean.
1521
+ * @throws `capability` (rejects) The manifest does not declare
1522
+ * `playback.control`.
1523
+ *
1524
+ * @example Make ← and → jump 10 seconds to keyframes
1525
+ * The arrow keys now jump 10 seconds and land on keyframes, which is fast
1526
+ * on large files. The newest call of any plugin wins and is withdrawn
1527
+ * when that plugin stops, so a plugin offering this as a setting applies
1528
+ * it on activation.
1529
+ * ```ts
1530
+ * await plugin.player.setStepSeek({ seconds: 10, keyframes: true });
1531
+ * ```
1532
+ *
1533
+ * @since 1.0.0
1534
+ */
1535
+ setStepSeek(options: {
1536
+ seconds: number;
1537
+ keyframes?: boolean;
1538
+ }): Promise<void>;
1539
+ /**
1540
+ * The chapters of the current media (empty without media or chapters),
1541
+ * read on demand; `sourceId` tells which source they belong to.
1542
+ * `playback.read`.
1543
+ *
1544
+ * @capability playback.read
1545
+ * @throws `capability` (rejects) The manifest does not declare
1546
+ * `playback.read`.
1547
+ *
1548
+ * @example List the chapters of the open file
1549
+ * The plugin reads the chapter titles of the current file to show them in
1550
+ * its panel. `chapters` asks the player when called; `sourceId` says which
1551
+ * source they belong to, so a reply for a file that was replaced meanwhile
1552
+ * can be dropped.
1553
+ * ```ts
1554
+ * const { sourceId, chapters } = await plugin.player.chapters();
1555
+ * if (sourceId === plugin.player.state.sourceId) // still the same file
1556
+ * console.log(chapters.map((chapter) => chapter.title));
1557
+ * ```
1558
+ *
1559
+ * @since 1.0.0
1560
+ */
1561
+ chapters(): Promise<{
1562
+ /** The source the chapters belong to (compare with `state.sourceId`). */
1563
+ sourceId: number;
1564
+ /** In playback order. */
1565
+ chapters: Chapter[];
1566
+ }>;
1567
+ /**
1568
+ * A-B loop: on reaching `b`, jump back to `a` (seconds, `0 ≤ a < b ≤
1569
+ * duration`), `count` times (positive integer; omitted = endless); `null`
1570
+ * stops it. After the last jump back `state.loop` becomes null.
1571
+ * `invalid` out of range, `unsupported` for a source that cannot seek,
1572
+ * `unavailable` without ready media. A new source clears it.
1573
+ *
1574
+ * @capability playback.control
1575
+ * @throws `invalid` (rejects) `a`/`b` out of range or `count` not a positive
1576
+ * integer.
1577
+ * @throws `unsupported` (rejects) The source cannot seek, or is a generated
1578
+ * stream.
1579
+ * @throws `unavailable` (rejects) No ready media.
1580
+ * @throws `stale` (rejects) The source changed since the state the call is
1581
+ * based on (another file, a close, or any pause, seek
1582
+ * or speed change by the user or another plugin).
1583
+ * @throws `capability` (rejects) The manifest does not declare
1584
+ * `playback.control`.
1585
+ *
1586
+ * @example Loop a passage three times
1587
+ * Playback repeats 1:00–1:30 three times, then goes on. The player jumps
1588
+ * back to `a` each time it reaches `b`; after the last repeat
1589
+ * `state.loop` becomes `null`, and a new source clears the loop.
1590
+ * ```ts
1591
+ * await plugin.player.setLoop({ a: 60, b: 90, count: 3 }); // seconds
1592
+ * ```
1593
+ *
1594
+ * @since 1.0.0
1595
+ */
1596
+ setLoop(loop: {
1597
+ a: number;
1598
+ b: number;
1599
+ count?: number;
1600
+ } | null, options?: Conditional): Promise<void>;
1601
+ /**
1602
+ * The output devices present now (not the system default entry). `playback.read`.
1603
+ *
1604
+ * @capability playback.read
1605
+ * @throws `capability` (rejects) The manifest does not declare
1606
+ * `playback.read`.
1607
+ *
1608
+ * @example Offer the audio output devices in a menu
1609
+ * A submenu lists the output devices present now, with a radio mark on the
1610
+ * one in use. `audioDevices` asks the player when called (devices come and
1611
+ * go), and `state.audioOutput` tells which one is active.
1612
+ * ```ts
1613
+ * // The devices present now; build the menu again when they change.
1614
+ * for (const device of await plugin.player.audioDevices())
1615
+ * plugin.commands.add({
1616
+ * id: `device.${device.id}`,
1617
+ * path: ["@audio", "Output", device.name],
1618
+ * radio: true,
1619
+ * checked: () => plugin.player.state.audioOutput?.active === device.id,
1620
+ * run: () => plugin.player.setAudioDevice(device.id),
1621
+ * });
1622
+ * ```
1623
+ *
1624
+ * @since 1.0.0
1625
+ */
1626
+ audioDevices(): Promise<AudioDevice[]>;
1627
+ /**
1628
+ * Play on this device while it is present, else on the system default
1629
+ * (`null` = always the default). Generated streams follow too. Kept for
1630
+ * this run only. `playback.control`.
1631
+ *
1632
+ * Unknown ids are accepted (`state.audioOutput.active` stays `null`); a
1633
+ * malformed id is `invalid`. Reverts to the default when this plugin
1634
+ * stops; save the choice yourself to restore it on activation.
1635
+ *
1636
+ * @capability playback.control
1637
+ * @throws `invalid` (rejects) A malformed id.
1638
+ * @throws `capability` (rejects) The manifest does not declare
1639
+ * `playback.control`.
1640
+ *
1641
+ * @example Restore the user's output device on start
1642
+ * The plugin plays on the device the user picked last time, or on the
1643
+ * system default when it is not connected. The choice lasts only for
1644
+ * this run and is withdrawn when the plugin stops, so the plugin saves
1645
+ * it itself and sets it again on activation.
1646
+ * ```ts
1647
+ * const store = plugin.storage.json("output", { defaults: { device: null as string | null } });
1648
+ * await plugin.player.setAudioDevice(store.value.device); // null: the system default
1649
+ * ```
1650
+ *
1651
+ * @since 1.0.0
1652
+ */
1653
+ setAudioDevice(id: string | null): Promise<void>;
1654
+ }