@vestra-player/sdk 1.8.0 → 1.10.0

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 (106) hide show
  1. package/CHANGELOG.md +64 -2
  2. package/README.md +2 -2
  3. package/bin/vestra-plugin.mjs +98 -106
  4. package/capability-scan.json +21 -1
  5. package/dist/api-requests.d.ts +15 -39
  6. package/dist/api-requests.js +28 -50
  7. package/dist/capability-scan.d.ts +1 -1
  8. package/dist/capability-scan.js +8 -9
  9. package/dist/condition-table.d.ts +1889 -0
  10. package/dist/condition-table.js +562 -0
  11. package/dist/docs-tree.json.gz +0 -0
  12. package/dist/docs.d.ts +1 -1
  13. package/dist/docs.js +1 -1
  14. package/dist/i18n-tools.d.ts +7 -0
  15. package/dist/i18n-tools.js +66 -3
  16. package/dist/index.d.ts +4 -5
  17. package/dist/manifest.d.ts +5 -0
  18. package/dist/manifest.js +9 -24
  19. package/dist/member-uses.d.ts +61 -0
  20. package/dist/member-uses.js +160 -0
  21. package/dist/player-runtime.d.ts +4 -2
  22. package/dist/player-runtime.js +4 -2
  23. package/dist/plugin/appearance.d.ts +1 -1
  24. package/dist/plugin/appearance.js +2 -2
  25. package/dist/plugin/bindings.d.ts +1 -1
  26. package/dist/plugin/bindings.js +2 -2
  27. package/dist/plugin/commands.js +1 -12
  28. package/dist/plugin/connection.d.ts +38 -8
  29. package/dist/plugin/connection.js +126 -37
  30. package/dist/plugin/drops.js +1 -1
  31. package/dist/plugin/index.d.ts +7 -0
  32. package/dist/plugin/index.js +22 -15
  33. package/dist/plugin/media.js +0 -12
  34. package/dist/plugin/mpv.js +39 -12
  35. package/dist/plugin/packages.js +1 -2
  36. package/dist/plugin/player/events.d.ts +17 -7
  37. package/dist/plugin/player/events.js +26 -9
  38. package/dist/plugin/player.d.ts +37 -13
  39. package/dist/plugin/player.js +133 -22
  40. package/dist/plugin/scope.d.ts +4 -1
  41. package/dist/plugin/scope.js +8 -0
  42. package/dist/plugin/services.d.ts +4 -4
  43. package/dist/plugin/services.js +7 -29
  44. package/dist/plugin/settings.js +1 -1
  45. package/dist/plugin/shaders.js +0 -2
  46. package/dist/plugin/stream.d.ts +2 -1
  47. package/dist/plugin/stream.js +2 -2
  48. package/dist/plugin/testing/commands.d.ts +3 -10
  49. package/dist/plugin/testing/commands.js +24 -37
  50. package/dist/plugin/testing/index.d.ts +133 -116
  51. package/dist/plugin/testing/index.js +198 -125
  52. package/dist/plugin/testing/media.d.ts +6 -0
  53. package/dist/plugin/testing/media.js +15 -2
  54. package/dist/plugin/testing/processing.js +1 -1
  55. package/dist/plugin/testing/services.js +0 -1
  56. package/dist/plugin/testing/source-events.d.ts +28 -0
  57. package/dist/plugin/testing/source-events.js +66 -0
  58. package/dist/plugin/testing/transport.js +5 -0
  59. package/dist/plugin/testing/triggers.d.ts +82 -0
  60. package/dist/plugin/testing/triggers.js +448 -0
  61. package/dist/plugin/timeline.d.ts +5 -6
  62. package/dist/plugin/timeline.js +7 -11
  63. package/dist/plugin/triggers.d.ts +55 -0
  64. package/dist/plugin/triggers.js +233 -0
  65. package/dist/plugin/types/base.d.ts +77 -87
  66. package/dist/plugin/types/commands.d.ts +384 -68
  67. package/dist/plugin/types/packages.d.ts +17 -55
  68. package/dist/plugin/types/playback.d.ts +382 -152
  69. package/dist/plugin/types/plugin-wire.d.ts +6 -36
  70. package/dist/plugin/types/processing.d.ts +10 -49
  71. package/dist/plugin/types/services.d.ts +11 -70
  72. package/dist/plugin/types/snapshots.d.ts +7 -60
  73. package/dist/plugin/types/sources.d.ts +2 -11
  74. package/dist/plugin/types/subtitles.d.ts +5 -26
  75. package/dist/plugin/types/ui-content.d.ts +1 -16
  76. package/dist/plugin/types/ui-layout.d.ts +53 -79
  77. package/dist/plugin/types/ui-locale.d.ts +5 -23
  78. package/dist/plugin/types/ui-shell.d.ts +13 -59
  79. package/dist/plugin/view/layout.js +1 -1
  80. package/dist/plugin/view.js +0 -2
  81. package/dist/plugin/when.d.ts +78 -4
  82. package/dist/plugin/when.js +182 -14
  83. package/dist/plugin/window.d.ts +1 -1
  84. package/dist/plugin/window.js +1 -1
  85. package/dist/plugin/wire-facade.js +1 -2
  86. package/dist/processing.d.ts +2 -3
  87. package/dist/protocol.d.ts +14 -0
  88. package/dist/protocol.js +14 -0
  89. package/dist/request-queue.js +1 -1
  90. package/dist/slint-version.d.ts +7 -0
  91. package/dist/slint-version.js +7 -0
  92. package/dist/subtitles.d.ts +1 -1
  93. package/dist/ts-plugin.d.ts +8 -15
  94. package/dist/ts-plugin.js +3 -141
  95. package/dist/wire.d.ts +22 -12
  96. package/dist/wire.js +17 -8
  97. package/llms.txt +6 -6
  98. package/package.json +1 -2
  99. package/dist/capabilities.d.ts +0 -107
  100. package/dist/capabilities.js +0 -69
  101. package/dist/capability-check.d.ts +0 -176
  102. package/dist/capability-check.js +0 -461
  103. package/dist/capability-rules.d.ts +0 -125
  104. package/dist/capability-rules.js +0 -192
  105. package/dist/host-capabilities.d.ts +0 -10
  106. package/dist/host-capabilities.js +0 -492
@@ -72,8 +72,6 @@ export interface TimelineRange {
72
72
  * refused one is reported to `onError`. Disposing the layer, its scope or
73
73
  * stopping the plugin removes the marks.
74
74
  *
75
- * @capability timeline.marks
76
- *
77
75
  * @example Clear the plugin's marks
78
76
  * The plugin's marks disappear from the seek bar while it keeps its
79
77
  * layer for later. An empty list clears the layer; other plugins' marks
@@ -110,7 +108,6 @@ export interface TimelineLayer extends Disposable {
110
108
  * );
111
109
  * ```
112
110
  *
113
- * @capability timeline.marks
114
111
  * @since 1.0.0
115
112
  */
116
113
  set(marks: {
@@ -127,7 +124,7 @@ export interface TimelineLayer extends Disposable {
127
124
  * marks. Disposing the layer, its scope or stopping the plugin removes both,
128
125
  * and a new source clears every layer.
129
126
  *
130
- * At most 100 ranges (`TIMELINE_LIMITS.ranges`), `0 ≤ start < end`, `end`
127
+ * At most 1000 ranges (`TIMELINE_LIMITS.ranges`), `0 ≤ start < end`, `end`
131
128
  * within the media while its duration is known, titles ≤ 100 characters.
132
129
  * Ranges may overlap. Failures go to `onError`; with `ifCurrent`, a
133
130
  * write for another source is dropped silently. A title is data or a
@@ -153,7 +150,6 @@ export interface TimelineLayer extends Disposable {
153
150
  * panel.onChange(show);
154
151
  * ```
155
152
  *
156
- * @capability timeline.marks
157
153
  * @since 1.6.9
158
154
  */
159
155
  setRanges(ranges: {
@@ -175,11 +171,9 @@ export interface TimelineLayer extends Disposable {
175
171
  * the layers by time and shows them. A new source clears every layer, so a
176
172
  * plugin publishes again for each file. `marks` is the merged list, which
177
173
  * any plugin can read. To run code when they change, listen with
178
- * `plugin.player.on("timeline.changed", …)` (needs `events`): `marks` and
174
+ * `plugin.player.on("timeline.changed", …)` (after `plugin.player.subscribe()`): `marks` and
179
175
  * `ranges` already hold the event's lists when the listener runs.
180
176
  *
181
- * @capability `timeline.marks` to publish; `playback.read` to read;
182
- * `events` to follow changes.
183
177
  *
184
178
  * @example Count the chapter marks other plugins published
185
179
  * The plugin reads how many chapter marks the seek bar shows, whoever
@@ -194,11 +188,11 @@ export interface TimelineLayer extends Disposable {
194
188
  * @category Playback
195
189
  */
196
190
  export interface Timeline {
197
- /** Every layer merged, by time (`playback.read`). Empty on a new source. */
191
+ /** Every layer merged, by time. Empty on a new source. */
198
192
  readonly marks: readonly TimelineMark[];
199
193
  /**
200
- * Every layer's ranges merged, by start (`playback.read`). Empty on a new
201
- * source. Kept current like `marks` (with `events`): read it in a
194
+ * Every layer's ranges merged, by start. Empty on a new
195
+ * source. Kept current like `marks` (after `plugin.player.subscribe()`): read it in a
202
196
  * {@link View.bind} function and the view follows it.
203
197
  *
204
198
  * @example Draw the published ranges in a seek bar of your own
@@ -222,15 +216,12 @@ export interface Timeline {
222
216
  * });
223
217
  * ```
224
218
  *
225
- * @capability playback.read
226
219
  * @since 1.6.9
227
220
  */
228
221
  readonly ranges: readonly TimelineRange[];
229
222
  /**
230
223
  * This plugin's layer (`timeline.marks`); a second call throws.
231
224
  *
232
- * @capability timeline.marks
233
- *
234
225
  * @example Publish this plugin's marks
235
226
  * The plugin gets its one layer and puts two chapter marks on the seek
236
227
  * bar. Calling `layer()` again while the first layer is not disposed
@@ -269,11 +260,21 @@ export interface AudioTrack {
269
260
  title: string | null;
270
261
  /** Language tag, `null` when unknown. */
271
262
  language: string | null;
263
+ /**
264
+ * The container stream number (`ffmpeg -map 0:<n>`) of an embedded track,
265
+ * when the player can vouch for it; `null` for external tracks and when
266
+ * the player cannot tell, as for a subtitle track. The SDK always sets
267
+ * it; it is optional only so that an `AudioTrack` written out in full
268
+ * before 1.10.0 (a test's fixture) still type-checks.
269
+ *
270
+ * @since 1.10.0
271
+ */
272
+ streamIndex?: number | null;
272
273
  }
273
274
  /**
274
275
  * An immutable view of the player. Keep one to make a later call conditional on it.
275
276
  *
276
- * Without `events`, {@link Player.state} only updates at start and after
277
+ * Without `plugin.player.subscribe()`, {@link Player.state} only updates at start and after
277
278
  * this plugin's own operations.
278
279
  *
279
280
  * @see {@link Player.state}, [Control playback](../../../docs/guides/control-playback.md)
@@ -424,13 +425,10 @@ export interface Conditional {
424
425
  * A source this plugin opened with {@link Player.open}. It does not own
425
426
  * the source: the user or another plugin can replace it at any time, and
426
427
  * `current` then turns false. `ready` and `onEnd` follow the player state:
427
- * with `events` they react to the player's events, without it `ready`
428
- * polls the state every 100 ms (which needs `playback.read`). Disposing the
428
+ * after `plugin.player.subscribe()`, they react to the player's events, without it `ready`
429
+ * polls the state every 100 ms. Disposing the
429
430
  * scope that opened it does not close the media; call `close` for that.
430
431
  *
431
- * @capability That of {@link Player.open} (`playback.control`); `ready` and
432
- * `onEnd` follow the state through `events` and `playback.read`.
433
- *
434
432
  * @example Open a file and say when it ends
435
433
  * The file opens and plays, and the OSD says "Finished" when it reaches its
436
434
  * end on its own. The handle belongs to this source: `onEnd` fires only
@@ -451,8 +449,6 @@ export interface Media {
451
449
  * `replaced` (another source took over) or `ended`; with `AbortError` when
452
450
  * the signal aborts, after closing the media.
453
451
  *
454
- * @capability That of {@link Player.open}; `playback.read` or `events` to
455
- * see the state change.
456
452
  * @throws `failed` (rejects) The media could not be loaded.
457
453
  * @throws `replaced` (rejects) Another source took over first.
458
454
  * @throws `ended` (rejects) The media already played to the end.
@@ -481,8 +477,6 @@ export interface Media {
481
477
  /**
482
478
  * Called once each time a playthrough of this media ends naturally.
483
479
  *
484
- * @capability That of {@link Player.open}; `events` to hear the end.
485
- *
486
480
  * @example Play the next file when this one ends
487
481
  * When the plugin's file ends naturally, the next one opens. The listener
488
482
  * gets the state at the end; passing it as `ifCurrent` makes the next
@@ -505,10 +499,6 @@ export interface Media {
505
499
  /**
506
500
  * Close it if it is still the player's source; otherwise do nothing.
507
501
  *
508
- * @capability That of {@link Player.open} (`playback.control`).
509
- * @throws `capability` (rejects) The manifest does not declare
510
- * `playback.control`.
511
- *
512
502
  * @example Close the preview the plugin opened
513
503
  * The plugin closes the preview it opened, but leaves alone anything the
514
504
  * user opened since. `close` acts only while this media is still the
@@ -519,6 +509,7 @@ export interface Media {
519
509
  * await preview.close(); // a no-op when something else is playing now
520
510
  * ```
521
511
  *
512
+ * @throws `disabled` (rejects) The plugin is stopping.
522
513
  * @since 1.0.0
523
514
  */
524
515
  close(): Promise<void>;
@@ -551,7 +542,6 @@ export interface Media {
551
542
  * file, the user pausing) ends the gesture: `active` turns false and later
552
543
  * seeks resolve `false`.
553
544
  *
554
- * @capability playback.control
555
545
  * @see [Keep a slider responsive while dragging](../../../docs/guides/slider.md)
556
546
  * @since 1.0.0
557
547
  * @category Playback
@@ -586,9 +576,6 @@ export interface Scrub {
586
576
  * bar.on("dragMove", (seconds: number) => void scrub?.seek(seconds, { keyframes }));
587
577
  * ```
588
578
  *
589
- * @capability playback.control
590
- * @throws `capability` (rejects) The manifest does not declare
591
- * `playback.control`.
592
579
  * @throws `stale` (rejects) The source changed from outside while this
593
580
  * seek was being sent (a superseded target or an ended gesture resolves
594
581
  * `false` instead).
@@ -604,8 +591,6 @@ export interface Scrub {
604
591
  /**
605
592
  * End the gesture; later seeks resolve `false`.
606
593
  *
607
- * @capability playback.control
608
- *
609
594
  * @example End the gesture when the user lets go
610
595
  * Releasing the slider ends the gesture, so a late `dragMove` cannot move
611
596
  * playback any more. After `end`, `seek` resolves `false` without doing
@@ -686,8 +671,6 @@ export type StreamStartError = PluginError & {
686
671
  * another source replaces it or the user closes it (`onStop` with `null`),
687
672
  * or when it fails (`onStop` with the error).
688
673
  *
689
- * @capability producer.av and playback.control
690
- *
691
674
  * @example Stop the stream from a menu item
692
675
  * A menu item ends the plugin's generated stream and closes it as the
693
676
  * player's source. `stop` closes the source first and then the frame
@@ -722,11 +705,9 @@ export interface Stream extends Disposable {
722
705
  * The player retires a stream's producer as soon as it is replaced or
723
706
  * closed; the SDK reads the player's state to tell that from a failure
724
707
  * (before 1.5.7 a replaced or closed stream could get `unavailable`
725
- * "producer absent"). Without `playback.read` a failure the SDK has not
708
+ * "producer absent"). Without `plugin.player.read()` a failure the SDK has not
726
709
  * seen yet is reported as null.
727
710
  *
728
- * @capability producer.av
729
- *
730
711
  * @example Tell the user why the stream stopped
731
712
  * The OSD explains a failure, and nothing is said when the user simply
732
713
  * opened another file. The listener runs only for stops from outside the
@@ -749,7 +730,6 @@ export interface Stream extends Disposable {
749
730
  * so stopping never shows as a playback failure. `dispose()` and
750
731
  * deactivation do the same.
751
732
  *
752
- * @capability producer.av and playback.control
753
733
  * @throws Whatever code closing the player's source failed with (the
754
734
  * frame connection and the producer are released either way). A
755
735
  * stream that is no longer the source just resolves.
@@ -883,13 +863,52 @@ export interface PlaybackStats {
883
863
  /** Seconds of media buffered ahead by the demuxer. */
884
864
  cacheSeconds: number | null;
885
865
  }
866
+ /**
867
+ * An open stream of the player's state ({@link Player.stream}).
868
+ *
869
+ * @remarks
870
+ * While it is open the player keeps the plugin running. It ends with
871
+ * {@link StateStream.stop}, when the scope that opened it is disposed, and
872
+ * when the plugin stops; it is not kept through standby.
873
+ *
874
+ * @example Follow the state while a panel is shown
875
+ * The stream lives only as long as what shows the state: it is opened
876
+ * with the scope of the panel's content and ends when that scope is
877
+ * disposed, so the plugin may go to standby afterwards.
878
+ * ```ts
879
+ * declare function draw(state: PlayerState): void;
880
+ * // ---cut---
881
+ * const shown = plugin.scope();
882
+ * shown.player.stream(draw); // stops when `shown` is disposed
883
+ * // … later, when the panel goes away:
884
+ * await shown.dispose();
885
+ * ```
886
+ *
887
+ * @since 1.10.0
888
+ * @category Playback
889
+ */
890
+ export interface StateStream {
891
+ /**
892
+ * Stop the stream: its listener is not called again. A second call does
893
+ * nothing. When no other stream is open, nothing of the streams keeps the
894
+ * plugin running any more.
895
+ *
896
+ * @throws Never.
897
+ *
898
+ * @example See Player.stream
899
+ * {@link Player.stream}
900
+ *
901
+ * @since 1.10.0
902
+ */
903
+ stop(): void;
904
+ }
886
905
  /**
887
906
  * `plugin.player`: playback state and controls.
888
907
  *
889
- * Capabilities: reading (`state` at start, `refresh`, `stats`, `chapters`,
890
- * `audioDevices`) needs `playback.read`; live updates and `onChange` need
891
- * `events`; every control needs `playback.control`; `openStream` needs
892
- * `producer.av` as well as `playback.control`.
908
+ * Call `plugin.player.subscribe()` and `await plugin.player.read()` first in `activate`:
909
+ * `read()` fills `state` once and keeps it current after this plugin's own
910
+ * calls; `subscribe()` keeps it, and every `onChange`, current with changes
911
+ * made elsewhere.
893
912
  *
894
913
  * Controls are conditional (see {@link Conditional}): they fail with
895
914
  * `stale` and do nothing when the source changed since the state you saw.
@@ -912,7 +931,7 @@ export interface PlaybackStats {
912
931
  * @remarks
913
932
  * `plugin.player` is the player's one source: what is open, its phase and
914
933
  * position, and the controls. `state` is a snapshot the SDK keeps current
915
- * from the player's events (with `events`) and refreshes after this
934
+ * from the player's events (after `plugin.player.subscribe()`) and refreshes after this
916
935
  * plugin's own calls; `onChange` runs after it changed. Every control is
917
936
  * conditional: it acts on the state the plugin last saw and fails with
918
937
  * `stale` when the source changed meanwhile: another file, a close, or any
@@ -921,8 +940,6 @@ export interface PlaybackStats {
921
940
  * only the plugin's own handles (a stream, its sequence provider, its
922
941
  * output device) are withdrawn.
923
942
  *
924
- * @capability `playback.read` to read; `playback.control` to control;
925
- * `events` to follow changes made elsewhere; `producer.av` for
926
943
  * {@link Player.openStream}.
927
944
  *
928
945
  * @see [Control playback](../../../docs/guides/control-playback.md)
@@ -933,16 +950,14 @@ export interface Player {
933
950
  /**
934
951
  * Latest state; always newer than anything delivered before.
935
952
  *
936
- * With `events` the SDK follows the player's events for this copy from
953
+ * After `plugin.player.subscribe()`, the SDK follows the player's events for this copy from
937
954
  * the plugin's start; without it the copy moves only with the start-up
938
- * read and the plugin's own calls (`playback.read`).
955
+ * read and the plugin's own calls.
939
956
  */
940
957
  readonly state: PlayerState;
941
958
  /**
942
- * The state changed (needs `events` for outside changes).
959
+ * The state changed (outside changes after `plugin.player.subscribe()`).
943
960
  *
944
- * @capability events (for changes made elsewhere; without it the listener
945
- * runs only after this plugin's own calls)
946
961
  *
947
962
  * @example Show the position while it plays
948
963
  * The OSD block shows the position, updated as playback moves. The SDK
@@ -959,6 +974,75 @@ export interface Player {
959
974
  * @since 1.0.0
960
975
  */
961
976
  onChange(listener: (state: PlayerState) => void): Disposable;
977
+ /**
978
+ * Follow the player's state while something needs it continuously: a
979
+ * window or panel that shows the position, a meter.
980
+ *
981
+ * @remarks
982
+ * `listener` runs with the current state as soon as the SDK has it (one
983
+ * read of the player's state right after the call), then with every
984
+ * change the player sends: about ten times a second while playing, at
985
+ * once when the phase, pause, speed or volume changes. Before each call
986
+ * the SDK updates {@link Player.state}; after each call an update pass
987
+ * runs, so {@link View.bind} functions and command states that read
988
+ * `plugin.player.state` follow the stream. It needs no
989
+ * {@link Player.subscribe}: the stream itself makes the state follow the
990
+ * player while it is open.
991
+ *
992
+ * **While a stream is open the player keeps the plugin running**: it is
993
+ * a listener (its log names it `a stream opened at main.ts:12`). Open it
994
+ * when the thing that shows the state appears and stop it when that goes
995
+ * away; nothing of a stopped stream keeps the plugin running. A plugin
996
+ * that only needs to know that something happened (a file opened, ready,
997
+ * ended) uses {@link Player.on} with a source event instead, which lets
998
+ * it go to standby.
999
+ *
1000
+ * Several streams may be open; each listener is called. A stream ends
1001
+ * with {@link StateStream.stop}, when its scope is disposed, and when the
1002
+ * plugin stops; it is not kept through standby. After the last one ends
1003
+ * `plugin.player.state` keeps the last snapshot, and without
1004
+ * {@link Player.subscribe} it no longer follows changes made elsewhere.
1005
+ * {@link Player.subscribe} and {@link Player.onChange} keep working as
1006
+ * before.
1007
+ *
1008
+ * The player judges what keeps a plugin running when the plugin becomes
1009
+ * ready. A stream that is open then counts as it does today for a
1010
+ * listener held at the ready: the plugin keeps running for that run, also
1011
+ * after the stream stops. Open the stream after `activate`, when what
1012
+ * shows the state appears.
1013
+ *
1014
+ * Errors the listener throws or rejects with go to
1015
+ * {@link Scope.onError}, as for every handler.
1016
+ *
1017
+ * @param listener - Receives the state now and at every change.
1018
+ * @returns The open stream; it is stopped with the scope.
1019
+ *
1020
+ * @throws `invalid` (throws) `listener` is not a function.
1021
+ *
1022
+ * @example Show the time left while a window is open
1023
+ * A tool window shows how much of the file is left, updated as it plays.
1024
+ * The stream starts when the window is shown and stops when the user
1025
+ * closes it, so the plugin can go to standby afterwards.
1026
+ * ```ts
1027
+ * const view = plugin.windows.create("ui/left.slint");
1028
+ * let feed: StateStream | undefined;
1029
+ * view.onClose(() => feed?.stop()); // closed: nothing keeps the plugin running
1030
+ * plugin.commands.add({
1031
+ * id: "left",
1032
+ * path: ["Tools", "Time Left"],
1033
+ * run: async () => {
1034
+ * await view.show();
1035
+ * feed?.stop(); // one stream per window, also when shown again
1036
+ * feed = plugin.player.stream((s) =>
1037
+ * view.set({ text: `${Math.round((s.duration ?? 0) - (s.position ?? 0))} s` }),
1038
+ * );
1039
+ * },
1040
+ * });
1041
+ * ```
1042
+ *
1043
+ * @since 1.10.0
1044
+ */
1045
+ stream(listener: (state: PlayerState) => void): StateStream;
962
1046
  /**
963
1047
  * Listen to one event of the player, with its data as the player sent
964
1048
  * it: no state copy, no comparison.
@@ -972,8 +1056,8 @@ export interface Player {
972
1056
  * listener of the plugin: the player keeps the plugin running while one
973
1057
  * exists (unless the event is one the player wakes a stopped plugin for),
974
1058
  * and its log names where the plugin added it
975
- * (`a listener added at main.ts:12`). Every name, its payload and its
976
- * capability: [Events](../../../docs/reference/events.md).
1059
+ * (`a listener added at main.ts:12`). Every name, its payload and
1060
+ * whether it waits for `subscribe()`: [Events](../../../docs/reference/events.md).
977
1061
  *
978
1062
  * Unlike {@link Player.onChange} it does not start the SDK's copy of the
979
1063
  * state: `plugin.player.state` is not kept current by it, and the
@@ -994,12 +1078,11 @@ export interface Player {
994
1078
  * {@link Scope.state} field re-runs only its readers, and
995
1079
  * {@link Scope.update} re-runs everything.
996
1080
  *
997
- * Each event needs a capability: `events` for most, `bindings.manage` for
998
- * `bindings.changed`, `commands` for `commands.keys`, `video.upscaling` for
999
- * `video.upscaling.changed`, `video.motion` for `video.motion.changed`,
1000
- * none for `packages.changed`. Without it the
1001
- * listener never runs (for `events`, a warning in the log says so). Added
1002
- * during `activate`, that fails the activation.
1081
+ * `source.state`, `playback.backend`, `window.state`,
1082
+ * `timeline.changed`, `appearance.changed` and `resolvers.fileTypes`
1083
+ * reach the plugin only after {@link Player.subscribe}; before it their
1084
+ * listener never runs (a warning in the log says so once). The other
1085
+ * events arrive from the first listener.
1003
1086
  *
1004
1087
  * @param event - The event's name.
1005
1088
  * @param listener - Receives each event's data.
@@ -1008,8 +1091,6 @@ export interface Player {
1008
1091
  * @throws `invalid` (throws) `event` is not a {@link HostEvent} name, or
1009
1092
  * `listener` is not a function.
1010
1093
  *
1011
- * @capability That of the event: `events`, or `bindings.manage`,
1012
- * `commands`, `video.upscaling`, `video.motion` for the events named above.
1013
1094
  *
1014
1095
  * @example Push the speed to a panel as it changes
1015
1096
  * A bottom panel shows the playback speed. The listener gets each
@@ -1025,28 +1106,153 @@ export interface Player {
1025
1106
  */
1026
1107
  on<E extends HostEvent>(event: E, listener: (data: EventPayload<E>) => void): Disposable;
1027
1108
  /**
1028
- * Read the state from the player now (`playback.read`).
1109
+ * Listen to one of the player's discrete source events: a source starts
1110
+ * to open, is ready, or ended.
1029
1111
  *
1030
- * @capability playback.read
1031
- * @throws `capability` (rejects) The manifest does not declare
1032
- * `playback.read`.
1112
+ * @remarks
1113
+ * `event` is a {@link SourceEvent} name; `listener` gets that event's
1114
+ * data, typed {@link SourceEventPayloads}, with `state` as a
1115
+ * {@link PlayerState}. The events arrive from the first listener,
1116
+ * without {@link Player.subscribe}, and a listener of one does not keep
1117
+ * the plugin running: the player starts a plugin in standby to deliver
1118
+ * them, and an event that arrives while the plugin starts waits for its
1119
+ * activation. `source.ended` with `reason: "quit"` reaches only a
1120
+ * plugin that is running when the player quits. As for every
1121
+ * {@link Player.on} listener, no full update pass follows it.
1122
+ *
1123
+ * @param event - The event's name.
1124
+ * @param listener - Receives each event's data.
1125
+ * @returns A handle that stops listening; it is disposed with the scope.
1126
+ *
1127
+ * @throws `invalid` (throws) `event` is not an event name, or
1128
+ * `listener` is not a function.
1129
+ *
1130
+ * @example Remember where each file was left
1131
+ * A plugin stores the position at which each file stopped playing. The
1132
+ * ended source's last state comes with the event, also when another
1133
+ * file replaced it.
1134
+ * ```ts
1135
+ * const saved = plugin.storage.json("positions", {
1136
+ * defaults: {} as Record<string, number>,
1137
+ * });
1138
+ * plugin.player.on("source.ended", ({ state, reason }) => {
1139
+ * if (reason === "natural" || state.source === null) return;
1140
+ * saved.save({ ...saved.value, [state.source]: state.position ?? 0 });
1141
+ * });
1142
+ * ```
1143
+ *
1144
+ * @since 1.10.0
1145
+ */
1146
+ on<E extends SourceEvent>(event: E, listener: (data: SourceEventPayloads[E]) => void): Disposable;
1147
+ /**
1148
+ * Read the state from the player now.
1033
1149
  *
1034
1150
  * @example Read the state before deciding
1035
1151
  * A command reads the newest state from the player before acting, even
1036
- * without `events`. `refresh` asks the player and resolves with the new
1152
+ * without `plugin.player.subscribe()`. `refresh` asks the player and resolves with the new
1037
1153
  * snapshot; `player.state` holds it afterwards.
1038
1154
  * ```ts
1039
1155
  * const state = await plugin.player.refresh();
1040
1156
  * if (state.phase === "ready") await plugin.osd.show("{} s left", [((state.duration ?? 0) - (state.position ?? 0)).toFixed(0)]);
1041
1157
  * ```
1042
1158
  *
1159
+ * @throws `disabled` (rejects) The plugin is stopping.
1043
1160
  * @since 1.0.0
1044
1161
  */
1045
1162
  refresh(): Promise<PlayerState>;
1046
1163
  /**
1047
- * True if nothing changed the source since `state` was observed.
1164
+ * Turn event delivery on for this run and follow the player's state from
1165
+ * now on.
1166
+ *
1167
+ * @remarks
1168
+ * Call it first in `activate`. From then on the player's events reach
1169
+ * this plugin: `plugin.player.state` follows changes made elsewhere (the
1170
+ * user, the player, another plugin), and so does every listener of
1171
+ * {@link Player.on}, {@link Player.onChange} and the other `onChange`
1172
+ * methods, and every {@link View.bind} function that reads a state.
1173
+ * Without the call a plugin's states move only after its own calls, and
1174
+ * a listener of `source.state`, `playback.backend`, `window.state`,
1175
+ * `timeline.changed`, `appearance.changed` or `resolvers.fileTypes`
1176
+ * never runs (a warning in the log says so once). A listener added
1177
+ * before the call starts to hear events at the call.
1178
+ *
1179
+ * It sends one request (the subscription of the state copy) and returns
1180
+ * at once; a failure of that request fails the activation. A second call
1181
+ * does nothing. The copy is a copy, not a listener: it keeps no plugin
1182
+ * running.
1183
+ *
1184
+ * @example Follow the player from the start
1185
+ * A bottom panel shows the playback speed and follows every change, also
1186
+ * one the user makes in the player's menus. `subscribe` turns the
1187
+ * player's events on and `read` fetches the state once, so the bound
1188
+ * function has the current speed at its first run and runs again
1189
+ * whenever it changes.
1190
+ * ```ts
1191
+ * import type { Plugin } from "@vestra-player/sdk";
1192
+ *
1193
+ * export default async function activate(plugin: Plugin) {
1194
+ * plugin.player.subscribe(); // events from now on
1195
+ * await plugin.player.read(); // the state as it is now
1196
+ * const bar = plugin.panels.mount("bottom", "ui/bar.slint");
1197
+ * bar.bind(() => ({ rate: `${plugin.player.state.rate.toFixed(2)}×` }));
1198
+ * }
1199
+ * ```
1200
+ *
1201
+ * @see {@link Player.read}
1202
+ * @since 1.9.0
1203
+ */
1204
+ subscribe(): void;
1205
+ /**
1206
+ * Read the player's state and the timeline's marks and ranges once, and
1207
+ * keep the state current after this plugin's own actions.
1208
+ *
1209
+ * @remarks
1210
+ * Call it first in `activate` (after {@link Player.subscribe}, when the
1211
+ * plugin also follows events) and wait for it: `plugin.player.state`,
1212
+ * `plugin.timeline.marks` and `plugin.timeline.ranges` then hold what the
1213
+ * player has. Before the call `state` is the empty state (`phase:
1214
+ * "empty"`) and the lists are empty. From the call on the SDK also reads
1215
+ * the state again after {@link Host.run}, when a {@link Media} handle is
1216
+ * closed and when a stream of the plugin ends, as the player's own
1217
+ * controls would show it.
1218
+ *
1219
+ * A second call reads nothing and resolves when the first read is in.
1220
+ * To read the state again later, use {@link Player.refresh}.
1221
+ *
1222
+ * @returns Resolves once the state and the timeline are read.
1223
+ *
1224
+ * @throws `disabled` (rejects) The plugin is stopping. The next call
1225
+ * reads again.
1226
+ *
1227
+ * @example Read the state before using it
1228
+ * A command shows how much of the file is left. `read` fetches the state
1229
+ * once during activation, so `state` is current when the command first
1230
+ * runs; without `subscribe` it moves only after this plugin's own calls,
1231
+ * so the command asks for it again with `refresh`.
1232
+ * ```ts
1233
+ * import type { Plugin } from "@vestra-player/sdk";
1048
1234
  *
1049
- * @capability None.
1235
+ * export default async function activate(plugin: Plugin) {
1236
+ * await plugin.player.read(); // state is current from here
1237
+ * plugin.commands.add({
1238
+ * id: "left",
1239
+ * path: ["Tools", "Time Left"],
1240
+ * enabled: () => plugin.player.state.phase === "ready",
1241
+ * run: async () => {
1242
+ * // No events: ask the player for the position now.
1243
+ * const { duration, position } = await plugin.player.refresh();
1244
+ * await plugin.osd.show("{} s left", [((duration ?? 0) - (position ?? 0)).toFixed(0)]);
1245
+ * },
1246
+ * });
1247
+ * }
1248
+ * ```
1249
+ *
1250
+ * @see {@link Player.subscribe}
1251
+ * @since 1.9.0
1252
+ */
1253
+ read(): Promise<void>;
1254
+ /**
1255
+ * True if nothing changed the source since `state` was observed.
1050
1256
  *
1051
1257
  * @example Drop a result that arrives after the file changed
1052
1258
  * A slow lookup for the current file is shown only if that file is still
@@ -1074,7 +1280,6 @@ export interface Player {
1074
1280
  * extension a file resolver claims (the source is then a stream that
1075
1281
  * plugin generates; `paused` reaches it).
1076
1282
  *
1077
- * @capability playback.control
1078
1283
  * @throws `stale` (rejects) `ifCurrent` no longer holds; nothing was opened.
1079
1284
  * @throws `replaced` (rejects) Accepted, then another source took over
1080
1285
  * before it finished (for example while a URL was still being resolved).
@@ -1090,8 +1295,6 @@ export interface Player {
1090
1295
  * returned (for example split streams with different headers).
1091
1296
  * @throws `unavailable` (rejects) The stream a file resolver prepared was
1092
1297
  * not ready to play.
1093
- * @throws `capability` (rejects) The manifest does not declare
1094
- * `playback.control`.
1095
1298
  *
1096
1299
  * @example Open a file paused
1097
1300
  * The file opens at its start without playing. `open` resolves once the
@@ -1110,8 +1313,8 @@ export interface Player {
1110
1313
  signal?: AbortSignal;
1111
1314
  } & Conditional): Promise<Media>;
1112
1315
  /**
1113
- * Start a source whose frames this plugin generates. Needs `producer.av`
1114
- * and `playback.control` (the stream becomes the player's source, like
1316
+ * Start a source whose frames this plugin generates (the stream becomes
1317
+ * the player's source, like
1115
1318
  * {@link Player.open}).
1116
1319
  *
1117
1320
  * The SDK calls `frame()` on the audio clock and handles prefill,
@@ -1142,7 +1345,6 @@ export interface Player {
1142
1345
  * stream.onStop((error) => error && plugin.osd.show(error.message));
1143
1346
  * ```
1144
1347
  *
1145
- * @capability producer.av and playback.control
1146
1348
  * @throws `timeout` (rejects) A {@link StreamStartError}: the stream did not
1147
1349
  * start in time.
1148
1350
  * @throws `stream` (rejects) The player failed to start the stream.
@@ -1158,15 +1360,12 @@ export interface Player {
1158
1360
  /**
1159
1361
  * Pause or resume.
1160
1362
  *
1161
- * @capability playback.control
1162
1363
  * @throws `stale` (rejects) The source changed since the state the call is
1163
1364
  * based on (another file, a close, or any pause, seek
1164
1365
  * or speed change by the user or another plugin); nothing was done.
1165
1366
  * @throws `invalid` (rejects) Nothing is open.
1166
1367
  * @throws `busy` (rejects) A generated stream is still handling a previous
1167
1368
  * control.
1168
- * @throws `capability` (rejects) The manifest does not declare
1169
- * `playback.control`.
1170
1369
  *
1171
1370
  * @example Pause, but only the file the user was watching
1172
1371
  * A "pause on lock" helper pauses the current file and does nothing when
@@ -1189,7 +1388,6 @@ export interface Player {
1189
1388
  * the end there and plays on, unless the end was reached while paused or
1190
1389
  * by a frame step; a seek at or past the end leaves it ended and paused.
1191
1390
  *
1192
- * @capability playback.control
1193
1391
  * @throws `stale` (rejects) The source changed since the state the call is
1194
1392
  * based on (another file, a close, or any pause, seek
1195
1393
  * or speed change by the user or another plugin); nothing was done.
@@ -1199,8 +1397,6 @@ export interface Player {
1199
1397
  * cannot seek.
1200
1398
  * @throws `busy` (rejects) A generated stream is still handling a previous
1201
1399
  * control.
1202
- * @throws `capability` (rejects) The manifest does not declare
1203
- * `playback.control`.
1204
1400
  *
1205
1401
  * @example Jump back ten seconds
1206
1402
  * Playback jumps ten seconds back, never before the start. The target is
@@ -1219,7 +1415,6 @@ export interface Player {
1219
1415
  /**
1220
1416
  * Set the playback speed.
1221
1417
  *
1222
- * @capability playback.control
1223
1418
  * @throws `stale` (rejects) The source changed since the state the call is
1224
1419
  * based on (another file, a close, or any pause, seek
1225
1420
  * or speed change by the user or another plugin); nothing was done.
@@ -1229,8 +1424,6 @@ export interface Player {
1229
1424
  * cannot change speed.
1230
1425
  * @throws `busy` (rejects) A generated stream is still handling a previous
1231
1426
  * control.
1232
- * @throws `capability` (rejects) The manifest does not declare
1233
- * `playback.control`.
1234
1427
  *
1235
1428
  * @example Play at one and a half times the speed
1236
1429
  * Playback speeds up to 1.5×, with the speed on the OSD. `setRate` sets
@@ -1249,15 +1442,12 @@ export interface Player {
1249
1442
  /**
1250
1443
  * Play from the start (the "replay" after the end).
1251
1444
  *
1252
- * @capability playback.control
1253
1445
  * @throws `stale` (rejects) The source changed since the state the call is
1254
1446
  * based on (another file, a close, or any pause, seek
1255
1447
  * or speed change by the user or another plugin); nothing was done.
1256
1448
  * @throws `invalid` (rejects) Nothing is open.
1257
1449
  * @throws `unsupported` (rejects) The source is a generated stream, which
1258
1450
  * cannot restart.
1259
- * @throws `capability` (rejects) The manifest does not declare
1260
- * `playback.control`.
1261
1451
  *
1262
1452
  * @example Replay a file after it ended
1263
1453
  * A Replay button starts the file again from its start once it has ended.
@@ -1273,12 +1463,9 @@ export interface Player {
1273
1463
  /**
1274
1464
  * Close the current source.
1275
1465
  *
1276
- * @capability playback.control
1277
1466
  * @throws `stale` (rejects) The source changed since the state the call is
1278
1467
  * based on (another file, a close, or any pause, seek
1279
1468
  * or speed change by the user or another plugin); nothing was done.
1280
- * @throws `capability` (rejects) The manifest does not declare
1281
- * `playback.control`.
1282
1469
  *
1283
1470
  * @example Close the file when the sleep timer runs out
1284
1471
  * After 30 minutes the open file is closed, unless the user opened another
@@ -1301,8 +1488,6 @@ export interface Player {
1301
1488
  /**
1302
1489
  * Start a drag gesture from the current state.
1303
1490
  *
1304
- * @capability playback.control
1305
- *
1306
1491
  * @example Start a gesture when the user grabs the slider
1307
1492
  * A drag on the plugin's seek slider becomes one gesture whose seeks never
1308
1493
  * pile up. `scrub()` captures the current state; the gesture's seeks are
@@ -1325,11 +1510,8 @@ export interface Player {
1325
1510
  * Resolves `true` when this request was applied, `false` if superseded.
1326
1511
  * `volume` is 0–200.
1327
1512
  *
1328
- * @capability playback.control
1329
1513
  * @throws `invalid` (rejects) `volume` outside 0–200, or `muted` not a
1330
1514
  * boolean.
1331
- * @throws `capability` (rejects) The manifest does not declare
1332
- * `playback.control`.
1333
1515
  *
1334
1516
  * @example Duck the volume during an announcement
1335
1517
  * The volume drops to 30 while the plugin's announcement plays, then
@@ -1380,18 +1562,14 @@ export interface Player {
1380
1562
  * });
1381
1563
  * ```
1382
1564
  *
1383
- * @capability playback.control
1384
1565
  * @since 1.0.0
1385
1566
  */
1386
1567
  provideSequence(provider: SequenceProvider): Disposable;
1387
1568
  /**
1388
1569
  * Ask the provider to go forward / back. Rejects `unavailable` when it cannot.
1389
1570
  *
1390
- * @capability playback.control
1391
1571
  * @throws `unavailable` (rejects) There is no sequence provider, or it has
1392
1572
  * no next item.
1393
- * @throws `capability` (rejects) The manifest does not declare
1394
- * `playback.control`.
1395
1573
  *
1396
1574
  * @example Skip to the next item from a plugin button
1397
1575
  * The plugin's own Next button plays the next item of whichever plugin
@@ -1413,11 +1591,8 @@ export interface Player {
1413
1591
  /**
1414
1592
  * Ask the provider to go back. Rejects `unavailable` when it cannot.
1415
1593
  *
1416
- * @capability playback.control
1417
1594
  * @throws `unavailable` (rejects) There is no sequence provider, or it has
1418
1595
  * no previous item.
1419
- * @throws `capability` (rejects) The manifest does not declare
1420
- * `playback.control`.
1421
1596
  *
1422
1597
  * @example Go back to the previous item
1423
1598
  * The plugin's Previous button asks the sequence provider for the item
@@ -1441,10 +1616,6 @@ export interface Player {
1441
1616
  * Codec, size, frame counts and backend of the current playback.
1442
1617
  * `playback.read`; `video` and `audio` are `null` without a source.
1443
1618
  *
1444
- * @capability playback.read
1445
- * @throws `capability` (rejects) The manifest does not declare
1446
- * `playback.read`.
1447
- *
1448
1619
  * @example Show the video codec and size
1449
1620
  * The OSD shows something like "h264 1920×1080". `stats` asks the player
1450
1621
  * for the backend's own values at that moment; `video` is `null` without
@@ -1454,6 +1625,7 @@ export interface Player {
1454
1625
  * if (video) await plugin.osd.show("{} {}×{}", [video.codec ?? "?", video.width ?? 0, video.height ?? 0]);
1455
1626
  * ```
1456
1627
  *
1628
+ * @throws `disabled` (rejects) The plugin is stopping.
1457
1629
  * @since 1.0.0
1458
1630
  */
1459
1631
  stats(): Promise<PlaybackStats>;
@@ -1463,13 +1635,10 @@ export interface Player {
1463
1635
  * not exportable). It stays until the source changes. Rejects `invalid` for a
1464
1636
  * bad path, `unavailable` without ready media, `backend` when it cannot load.
1465
1637
  *
1466
- * @capability playback.control
1467
1638
  * @throws `invalid` (rejects) Not an absolute path to a file.
1468
1639
  * @throws `unavailable` (rejects) No ready media.
1469
1640
  * @throws `backend` (rejects) The player could not load the file.
1470
1641
  * @throws `stale` (rejects) `ifCurrent` no longer holds.
1471
- * @throws `capability` (rejects) The manifest does not declare
1472
- * `playback.control`.
1473
1642
  *
1474
1643
  * @example Add a dubbed audio file and switch to it
1475
1644
  * A separate audio file plays with the film instead of its own sound.
@@ -1490,14 +1659,11 @@ export interface Player {
1490
1659
  /**
1491
1660
  * Select one of `state.audioTracks` by id; `invalid` for an unknown id.
1492
1661
  *
1493
- * @capability playback.control
1494
1662
  * @throws `invalid` (rejects) No track with this id.
1495
1663
  * @throws `unavailable` (rejects) No ready media.
1496
1664
  * @throws `stale` (rejects) The source changed since the state the call is
1497
1665
  * based on (another file, a close, or any pause, seek
1498
1666
  * or speed change by the user or another plugin).
1499
- * @throws `capability` (rejects) The manifest does not declare
1500
- * `playback.control`.
1501
1667
  *
1502
1668
  * @example Switch to the next audio track
1503
1669
  * Each press of the plugin's key moves to the next audio track of the
@@ -1522,7 +1688,6 @@ export interface Player {
1522
1688
  * is current afterwards. One step at a time: a second call while one is
1523
1689
  * in flight rejects `busy`.
1524
1690
  *
1525
- * @capability playback.control
1526
1691
  * @throws `unsupported` (rejects) Nothing playable to step through (no
1527
1692
  * moving video: audio only, cover art, a generated stream), a backward
1528
1693
  * frame step on a source that cannot seek, or a keyframe step in either
@@ -1531,8 +1696,6 @@ export interface Player {
1531
1696
  * @throws `stale` (rejects) The source changed since the state the call is
1532
1697
  * based on (another file, a close, or any pause, seek
1533
1698
  * or speed change by the user or another plugin).
1534
- * @throws `capability` (rejects) The manifest does not declare
1535
- * `playback.control`.
1536
1699
  *
1537
1700
  * @example Step one frame forward for a close look
1538
1701
  * The picture advances by one frame and playback pauses. `step` resolves
@@ -1563,11 +1726,8 @@ export interface Player {
1563
1726
  * `false`: exact seeks, as before. `seconds` and `keyframes` are written as a
1564
1727
  * pair: the newest call sets both.
1565
1728
  *
1566
- * @capability playback.control
1567
1729
  * @throws `invalid` (rejects) `seconds` outside 0.1–3600 or not in tenths,
1568
1730
  * or `keyframes` not a boolean.
1569
- * @throws `capability` (rejects) The manifest does not declare
1570
- * `playback.control`.
1571
1731
  *
1572
1732
  * @example Make ← and → jump 10 seconds to keyframes
1573
1733
  * The arrow keys now jump 10 seconds and land on keyframes, which is fast
@@ -1587,11 +1747,7 @@ export interface Player {
1587
1747
  /**
1588
1748
  * The chapters of the current media (empty without media or chapters),
1589
1749
  * read on demand; `sourceId` tells which source they belong to.
1590
- * `playback.read`.
1591
1750
  *
1592
- * @capability playback.read
1593
- * @throws `capability` (rejects) The manifest does not declare
1594
- * `playback.read`.
1595
1751
  *
1596
1752
  * @example List the chapters of the open file
1597
1753
  * The plugin reads the chapter titles of the current file to show them in
@@ -1604,6 +1760,7 @@ export interface Player {
1604
1760
  * console.log(chapters.map((chapter) => chapter.title));
1605
1761
  * ```
1606
1762
  *
1763
+ * @throws `disabled` (rejects) The plugin is stopping.
1607
1764
  * @since 1.0.0
1608
1765
  */
1609
1766
  chapters(): Promise<{
@@ -1619,7 +1776,6 @@ export interface Player {
1619
1776
  * `invalid` out of range, `unsupported` for a source that cannot seek,
1620
1777
  * `unavailable` without ready media. A new source clears it.
1621
1778
  *
1622
- * @capability playback.control
1623
1779
  * @throws `invalid` (rejects) `a`/`b` out of range or `count` not a positive
1624
1780
  * integer.
1625
1781
  * @throws `unsupported` (rejects) The source cannot seek, or is a generated
@@ -1628,8 +1784,6 @@ export interface Player {
1628
1784
  * @throws `stale` (rejects) The source changed since the state the call is
1629
1785
  * based on (another file, a close, or any pause, seek
1630
1786
  * or speed change by the user or another plugin).
1631
- * @throws `capability` (rejects) The manifest does not declare
1632
- * `playback.control`.
1633
1787
  *
1634
1788
  * @example Loop a passage three times
1635
1789
  * Playback repeats 1:00–1:30 three times, then goes on. The player jumps
@@ -1647,11 +1801,7 @@ export interface Player {
1647
1801
  count?: number;
1648
1802
  } | null, options?: Conditional): Promise<void>;
1649
1803
  /**
1650
- * The output devices present now (not the system default entry). `playback.read`.
1651
- *
1652
- * @capability playback.read
1653
- * @throws `capability` (rejects) The manifest does not declare
1654
- * `playback.read`.
1804
+ * The output devices present now (not the system default entry).
1655
1805
  *
1656
1806
  * @example Offer the audio output devices in a menu
1657
1807
  * A submenu lists the output devices present now, with a radio mark on the
@@ -1669,22 +1819,20 @@ export interface Player {
1669
1819
  * });
1670
1820
  * ```
1671
1821
  *
1822
+ * @throws `disabled` (rejects) The plugin is stopping.
1672
1823
  * @since 1.0.0
1673
1824
  */
1674
1825
  audioDevices(): Promise<AudioDevice[]>;
1675
1826
  /**
1676
1827
  * Play on this device while it is present, else on the system default
1677
1828
  * (`null` = always the default). Generated streams follow too. Kept for
1678
- * this run only. `playback.control`.
1829
+ * this run only.
1679
1830
  *
1680
1831
  * Unknown ids are accepted (`state.audioOutput.active` stays `null`); a
1681
1832
  * malformed id is `invalid`. Reverts to the default when this plugin
1682
1833
  * stops; save the choice yourself to restore it on activation.
1683
1834
  *
1684
- * @capability playback.control
1685
1835
  * @throws `invalid` (rejects) A malformed id.
1686
- * @throws `capability` (rejects) The manifest does not declare
1687
- * `playback.control`.
1688
1836
  *
1689
1837
  * @example Restore the user's output device on start
1690
1838
  * The plugin plays on the device the user picked last time, or on the
@@ -1749,7 +1897,7 @@ export interface EventPayloads {
1749
1897
  };
1750
1898
  /** The main window: fullscreen, maximized, video area, picture-in-picture (what {@link WindowState} is made from). */
1751
1899
  "window.state": WindowFacts;
1752
- /** Every installed plugin, after an install, an uninstall or a change of one (needs no capability). */
1900
+ /** Every installed plugin, after an install, an uninstall or a change of one. */
1753
1901
  "packages.changed": PackageInfo[];
1754
1902
  /** A key binding changed somewhere; read them again with `plugin.bindings.list()`. */
1755
1903
  "bindings.changed": null;
@@ -1790,6 +1938,91 @@ export interface EventPayloads {
1790
1938
  * @category Playback
1791
1939
  */
1792
1940
  export type EventPayload<E extends HostEvent> = EventPayloads[E];
1941
+ /**
1942
+ * The player's discrete source events: one event per thing that happened
1943
+ * to a source, which {@link Player.on} listens to by name.
1944
+ *
1945
+ * @remarks
1946
+ * `source.opening`: a new source starts to open. `source.ready`: it is
1947
+ * loaded. `source.ended`: it left playback. For one source the order is
1948
+ * `opening`, `ready`, `ended` (no `ready` when it could not be
1949
+ * opened); when a source is replaced, the old one's `ended` comes before
1950
+ * the new one's `opening`. Unlike `source.state` they arrive without
1951
+ * {@link Player.subscribe}, and a listener of one does not keep the plugin
1952
+ * running: the player starts a plugin in standby to deliver them.
1953
+ * {@link SourceEventPayloads} says what each one carries.
1954
+ *
1955
+ * @example Scan each file once it is loaded
1956
+ * A plugin looks at every file the player loads. The listener gets the
1957
+ * state at that moment, so the plugin needs no stream of its own and the
1958
+ * player may stop it between files.
1959
+ * ```ts
1960
+ * declare function scan(path: string): Promise<void>;
1961
+ * // ---cut---
1962
+ * plugin.player.on("source.ready", async ({ state }) => {
1963
+ * if (state.source !== null) await scan(state.source);
1964
+ * });
1965
+ * ```
1966
+ *
1967
+ * @since 1.10.0
1968
+ * @category Playback
1969
+ */
1970
+ export type SourceEvent = "source.opening" | "source.ready" | "source.ended";
1971
+ /**
1972
+ * The data each {@link SourceEvent} carries, as the listener of
1973
+ * {@link Player.on} gets it.
1974
+ *
1975
+ * @remarks
1976
+ * `state` is the SDK's {@link PlayerState}, not the player's wire shape,
1977
+ * so it can be passed as `ifCurrent` and to {@link Player.isCurrent}.
1978
+ * The state of an opening or a ready is also taken into
1979
+ * `plugin.player.state` when it is newer than what the plugin has.
1980
+ *
1981
+ * @since 1.10.0
1982
+ * @category Playback
1983
+ */
1984
+ export interface SourceEventPayloads {
1985
+ /**
1986
+ * A new source starts to open (also the same file again, and
1987
+ * {@link Player.restart}). `state` is the player's state at that moment,
1988
+ * as a {@link PlayerState} (pass it as `ifCurrent` or to
1989
+ * {@link Player.isCurrent}); `previous` names the source that was open
1990
+ * before it, `null` when nothing was.
1991
+ */
1992
+ "source.opening": {
1993
+ /** The player's state as the source starts to open. */
1994
+ state: PlayerState;
1995
+ /** The source open before this one (`null`: nothing was open). */
1996
+ previous: {
1997
+ /** The previous source's id (`PlayerState.sourceId`). */
1998
+ sourceId: number;
1999
+ } | null;
2000
+ };
2001
+ /**
2002
+ * The source is loaded: its duration, tracks and seekability are known.
2003
+ * Once per opening, after its `source.opening`.
2004
+ */
2005
+ "source.ready": {
2006
+ /** The player's state as the source became ready. */
2007
+ state: PlayerState;
2008
+ };
2009
+ /**
2010
+ * A source left playback: it played to its end (`natural`), was closed
2011
+ * (`stopped`), another source took its place (`replaced`), it could not
2012
+ * be played (`error`, with the failure text in `error`), or the player
2013
+ * quits (`quit`, sent only to a plugin that is running then). `state` is
2014
+ * **that** source's last state, with its last position, not the
2015
+ * player's current one.
2016
+ */
2017
+ "source.ended": {
2018
+ /** The ended source's last state, as a {@link PlayerState}. */
2019
+ state: PlayerState;
2020
+ /** Why it left playback. */
2021
+ reason: "natural" | "stopped" | "replaced" | "error" | "quit";
2022
+ /** The failure text, when `reason` is `error` and the player has one. */
2023
+ error?: string;
2024
+ };
2025
+ }
1793
2026
  /**
1794
2027
  * A value of mpv, as JSON: what a property holds, a command returns or an
1795
2028
  * argument of `set` is (mpv's "node": nothing, a flag, a number, a string,
@@ -1803,8 +2036,9 @@ export type MpvValue = null | boolean | number | string | MpvValue[] | {
1803
2036
  };
1804
2037
  /**
1805
2038
  * `plugin.mpv`: mpv's own commands and properties, sent to the player's
1806
- * mpv as they are. Needs the capability `mpv`, which the store shows the
1807
- * user before installing.
2039
+ * mpv as they are. The capability scan puts `command` and `set` in its
2040
+ * `player` category, which the store shows the user before installing
2041
+ * ([Capability scan](../../../docs/reference/scan.md)).
1808
2042
  *
1809
2043
  * @example Turn mpv's debanding on and show whether it took effect
1810
2044
  * A plugin offers mpv's `deband` option, which the plugin API has no member
@@ -1847,11 +2081,12 @@ export type MpvValue = null | boolean | number | string | MpvValue[] | {
1847
2081
  * the upscaler, motion smoothing) stay in the chain beside it.
1848
2082
  *
1849
2083
  * A property a plugin set keeps its value after the plugin stops, until
1850
- * the player quits (what the capability `mpv` discloses); a plugin that
1851
- * wants it back sets it back. Observers end with the plugin. A filter
1852
- * or an observer keeps the plugin running.
2084
+ * the player quits (what the scan's `player` category discloses); a
2085
+ * plugin that wants it back sets it back. Observers end with the plugin.
2086
+ * A filter or an observer keeps the plugin running from the moment it is
2087
+ * added for the rest of that run, also after it is removed: the player
2088
+ * judges again at the plugin's next start.
1853
2089
  *
1854
- * @capability mpv
1855
2090
  * @see [mpv](../../../docs/reference/mpv.md)
1856
2091
  * @since 1.8.0
1857
2092
  * @category Playback
@@ -1879,8 +2114,6 @@ export interface Mpv {
1879
2114
  * await plugin.mpv.command(["vf", "remove", "@crisp"]);
1880
2115
  * ```
1881
2116
  *
1882
- * @capability mpv
1883
- * @throws `capability` (rejects) The manifest does not declare `mpv`.
1884
2117
  * @throws `invalid` (rejects) Not an array of a name and up to 31
1885
2118
  * arguments, or an argument that is not a string, number or boolean.
1886
2119
  * @throws `refused` (rejects) A command the channel does not carry; the
@@ -1906,8 +2139,6 @@ export interface Mpv {
1906
2139
  * await plugin.osd.show("Decoder: {}", [String(decoder)]);
1907
2140
  * ```
1908
2141
  *
1909
- * @capability mpv
1910
- * @throws `capability` (rejects) The manifest does not declare `mpv`.
1911
2142
  * @throws `invalid` (rejects) Not a property name.
1912
2143
  * @throws `refused` (rejects) The clipboard's properties.
1913
2144
  * @throws `backend` (rejects) mpv has no such property, or it has no
@@ -1933,8 +2164,6 @@ export interface Mpv {
1933
2164
  * await plugin.mpv.set("scale", before);
1934
2165
  * ```
1935
2166
  *
1936
- * @capability mpv
1937
- * @throws `capability` (rejects) The manifest does not declare `mpv`.
1938
2167
  * @throws `invalid` (rejects) Not a property name, or no value.
1939
2168
  * @throws `refused` (rejects) A property the channel does not carry; the
1940
2169
  * message names it and why.
@@ -1945,12 +2174,15 @@ export interface Mpv {
1945
2174
  set(name: string, value: MpvValue): Promise<void>;
1946
2175
  /**
1947
2176
  * Hear an mpv property's value now and after each change. The player
1948
- * sends the newest value at most every 100 ms. While a listener exists
1949
- * the player keeps the plugin running.
2177
+ * sends the newest value at most every 100 ms. From the first listener
2178
+ * on the player keeps the plugin running for the rest of the run, also
2179
+ * after the handle is disposed. As after every handler, an update pass
2180
+ * follows each call of the listener.
1950
2181
  *
1951
2182
  * @param name - The property, as mpv names it.
1952
2183
  * @param listener - Receives the value: first the current one, then
1953
- * each change.
2184
+ * each change. A listener added while the plugin already observes the
2185
+ * property gets its current value too, just after `observe` returns.
1954
2186
  * @returns A handle that stops listening; it is disposed with the scope.
1955
2187
  *
1956
2188
  * @example Follow the frame rate after filters
@@ -1965,8 +2197,6 @@ export interface Mpv {
1965
2197
  * });
1966
2198
  * ```
1967
2199
  *
1968
- * @capability mpv
1969
- * @throws `capability` (throws) The manifest does not declare `mpv`.
1970
2200
  * @throws `invalid` (throws) Not a property name, or no listener.
1971
2201
  * @throws `refused` (throws) The clipboard's properties.
1972
2202
  * @throws `limit` (through `onError`) More than 64 properties observed