@amazon/vinyl 2.0.0 → 3.0.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.
- package/dist/index.cjs +603 -317
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +622 -329
- package/dist/index.js.map +4 -4
- package/dist/test/benchmark.es5.js +8 -5
- package/dist/test/benchmark.js +228 -0
- package/dist/test/benchmark.js.map +4 -4
- package/dist/test/integ.es5.js +182 -156
- package/dist/test/integ.js +1853 -796
- package/dist/test/integ.js.map +4 -4
- package/dist/types/current/index.d.ts +4 -0
- package/dist/types/current/index.d.ts.map +1 -1
- package/dist/types/current/index.js +4 -0
- package/dist/types/current/streaming/AudioOptions.d.ts +39 -0
- package/dist/types/current/streaming/AudioOptions.d.ts.map +1 -0
- package/dist/types/current/streaming/AudioOptions.js +15 -0
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts.map +1 -1
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.js +5 -5
- package/dist/types/current/text/HtmlTextTrackRenderer.d.ts +60 -0
- package/dist/types/current/text/HtmlTextTrackRenderer.d.ts.map +1 -0
- package/dist/types/current/text/HtmlTextTrackRenderer.js +231 -0
- package/dist/types/current/text/SidecarTextTrackController.d.ts +65 -53
- package/dist/types/current/text/SidecarTextTrackController.d.ts.map +1 -1
- package/dist/types/current/text/SidecarTextTrackController.js +167 -154
- package/dist/types/current/text/SidecarTextTrackLoader.d.ts +5 -0
- package/dist/types/current/text/SidecarTextTrackLoader.d.ts.map +1 -1
- package/dist/types/current/text/SidecarTextTrackLoader.js +13 -7
- package/dist/types/current/text/TextTrack.d.ts +74 -20
- package/dist/types/current/text/TextTrack.d.ts.map +1 -1
- package/dist/types/current/text/TextTrack.js +20 -0
- package/dist/types/current/text/TextTrackRenderer.d.ts +24 -0
- package/dist/types/current/text/TextTrackRenderer.d.ts.map +1 -0
- package/dist/types/current/text/TextTrackRenderer.js +5 -0
- package/dist/types/current/text/mediaTextTrackProvider.d.ts +34 -0
- package/dist/types/current/text/mediaTextTrackProvider.d.ts.map +1 -0
- package/dist/types/current/text/mediaTextTrackProvider.js +42 -0
- package/dist/types/current/text/parseWebVtt.d.ts +16 -2
- package/dist/types/current/text/parseWebVtt.d.ts.map +1 -1
- package/dist/types/current/text/parseWebVtt.js +176 -48
- package/dist/types/current/text/pickPreferredTextTrack.d.ts +2 -1
- package/dist/types/current/text/pickPreferredTextTrack.d.ts.map +1 -1
- package/dist/types/current/text/pickPreferredTextTrack.js +6 -3
- package/dist/types/current/track/Track.d.ts +1 -1
- package/dist/types/current/track/dash/createDashFactories.d.ts +21 -10
- package/dist/types/current/track/dash/createDashFactories.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDashFactories.js +9 -21
- package/dist/types/current/track/hls/createHlsFactories.d.ts +21 -10
- package/dist/types/current/track/hls/createHlsFactories.d.ts.map +1 -1
- package/dist/types/current/track/hls/createHlsFactories.js +9 -21
- package/dist/types/current/track/mse/MseTrack.d.ts +1 -2
- package/dist/types/current/track/mse/MseTrack.d.ts.map +1 -1
- package/dist/types/current/track/mse/MseTrack.js +3 -7
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/types/current/vinyl/VinylOptions.d.ts +18 -40
- package/dist/types/current/vinyl/VinylOptions.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylOptions.js +12 -11
- package/dist/types/current/vinyl/VinylPlayer.d.ts +0 -6
- package/dist/types/current/vinyl/VinylPlayer.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylPlayer.js +2 -23
- package/dist/types/current/vinyl/createVinylFactories.d.ts +32 -18
- package/dist/types/current/vinyl/createVinylFactories.d.ts.map +1 -1
- package/dist/types/current/vinyl/createVinylFactories.js +6 -0
- package/dist/types/ts3.7/index.d.ts +4 -0
- package/dist/types/ts3.7/streaming/AudioOptions.d.ts +39 -0
- package/dist/types/ts3.7/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
- package/dist/types/ts3.7/text/HtmlTextTrackRenderer.d.ts +60 -0
- package/dist/types/ts3.7/text/SidecarTextTrackController.d.ts +65 -53
- package/dist/types/ts3.7/text/SidecarTextTrackLoader.d.ts +5 -0
- package/dist/types/ts3.7/text/TextTrack.d.ts +74 -20
- package/dist/types/ts3.7/text/TextTrackRenderer.d.ts +24 -0
- package/dist/types/ts3.7/text/mediaTextTrackProvider.d.ts +34 -0
- package/dist/types/ts3.7/text/parseWebVtt.d.ts +16 -2
- package/dist/types/ts3.7/text/pickPreferredTextTrack.d.ts +2 -1
- package/dist/types/ts3.7/track/Track.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/createDashFactories.d.ts +21 -10
- package/dist/types/ts3.7/track/hls/createHlsFactories.d.ts +21 -10
- package/dist/types/ts3.7/track/mse/MseTrack.d.ts +1 -2
- package/dist/types/ts3.7/vinyl/VinylOptions.d.ts +18 -40
- package/dist/types/ts3.7/vinyl/VinylPlayer.d.ts +0 -6
- package/dist/types/ts3.7/vinyl/createVinylFactories.d.ts +32 -18
- package/dist/types/ts4.1/index.d.ts +4 -0
- package/dist/types/ts4.1/streaming/AudioOptions.d.ts +39 -0
- package/dist/types/ts4.1/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
- package/dist/types/ts4.1/text/HtmlTextTrackRenderer.d.ts +60 -0
- package/dist/types/ts4.1/text/SidecarTextTrackController.d.ts +65 -53
- package/dist/types/ts4.1/text/SidecarTextTrackLoader.d.ts +5 -0
- package/dist/types/ts4.1/text/TextTrack.d.ts +74 -20
- package/dist/types/ts4.1/text/TextTrackRenderer.d.ts +24 -0
- package/dist/types/ts4.1/text/mediaTextTrackProvider.d.ts +34 -0
- package/dist/types/ts4.1/text/parseWebVtt.d.ts +16 -2
- package/dist/types/ts4.1/text/pickPreferredTextTrack.d.ts +2 -1
- package/dist/types/ts4.1/track/Track.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/createDashFactories.d.ts +21 -10
- package/dist/types/ts4.1/track/hls/createHlsFactories.d.ts +21 -10
- package/dist/types/ts4.1/track/mse/MseTrack.d.ts +1 -2
- package/dist/types/ts4.1/vinyl/VinylOptions.d.ts +18 -40
- package/dist/types/ts4.1/vinyl/VinylPlayer.d.ts +0 -6
- package/dist/types/ts4.1/vinyl/createVinylFactories.d.ts +32 -18
- package/dist/types/ts4.7/index.d.ts +4 -0
- package/dist/types/ts4.7/streaming/AudioOptions.d.ts +39 -0
- package/dist/types/ts4.7/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
- package/dist/types/ts4.7/text/HtmlTextTrackRenderer.d.ts +60 -0
- package/dist/types/ts4.7/text/SidecarTextTrackController.d.ts +65 -53
- package/dist/types/ts4.7/text/SidecarTextTrackLoader.d.ts +5 -0
- package/dist/types/ts4.7/text/TextTrack.d.ts +74 -20
- package/dist/types/ts4.7/text/TextTrackRenderer.d.ts +24 -0
- package/dist/types/ts4.7/text/mediaTextTrackProvider.d.ts +34 -0
- package/dist/types/ts4.7/text/parseWebVtt.d.ts +16 -2
- package/dist/types/ts4.7/text/pickPreferredTextTrack.d.ts +2 -1
- package/dist/types/ts4.7/track/Track.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/createDashFactories.d.ts +21 -10
- package/dist/types/ts4.7/track/hls/createHlsFactories.d.ts +21 -10
- package/dist/types/ts4.7/track/mse/MseTrack.d.ts +1 -2
- package/dist/types/ts4.7/vinyl/VinylOptions.d.ts +18 -40
- package/dist/types/ts4.7/vinyl/VinylPlayer.d.ts +0 -6
- package/dist/types/ts4.7/vinyl/createVinylFactories.d.ts +32 -18
- package/dist/unit/types/current/index.d.ts +2 -0
- package/dist/unit/types/current/index.d.ts.map +1 -1
- package/dist/unit/types/current/index.js +2 -0
- package/dist/unit/types/current/streaming/MseTrack.test.js +13 -7
- package/dist/unit/types/current/streaming/createDefaultMediaTimelineTransformer.test.js +8 -4
- package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.d.ts +2 -0
- package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.d.ts.map +1 -0
- package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.js +231 -0
- package/dist/unit/types/current/text/SidecarTextTrackController.test.js +432 -333
- package/dist/unit/types/current/text/SidecarTextTrackLoader.test.js +29 -0
- package/dist/unit/types/current/text/mediaTextTrackProvider.test.d.ts +2 -0
- package/dist/unit/types/current/text/mediaTextTrackProvider.test.d.ts.map +1 -0
- package/dist/unit/types/current/text/mediaTextTrackProvider.test.js +86 -0
- package/dist/unit/types/current/text/parseWebVtt.test.js +187 -6
- package/dist/unit/types/current/text/pickPreferredTextTrack.test.js +12 -1
- package/dist/unit/types/current/track/dash/createDashFactories.test.js +1 -2
- package/dist/unit/types/current/track/hls/buildHlsMediaTimeline.test.js +1 -2
- package/dist/unit/types/current/track/hls/createHlsFactories.test.js +1 -2
- package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/unit/types/current/vinyl/VinylPlayerTextTracks.test.js +102 -177
- package/dist/unit/types/current/vinyl/createVinylFactories.test.js +2 -0
- package/dist/vinylTestUtil/index.js +14 -8
- package/dist/vinylTestUtil/index.js.map +2 -2
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.js +5 -2
- package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.d.ts +3 -3
- package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.js +3 -3
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.js +3 -2
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.js +3 -2
- package/dist/vinylTestUtil/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/vinylTestUtil/types/ts3.7/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
- package/dist/vinylTestUtil/types/ts3.7/mock/text/MockTextTrackController.d.ts +3 -3
- package/dist/vinylTestUtil/types/ts3.7/mock/track/dash/createMockDashDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/ts3.7/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/ts4.1/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
- package/dist/vinylTestUtil/types/ts4.1/mock/text/MockTextTrackController.d.ts +3 -3
- package/dist/vinylTestUtil/types/ts4.1/mock/track/dash/createMockDashDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/ts4.1/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/ts4.7/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
- package/dist/vinylTestUtil/types/ts4.7/mock/text/MockTextTrackController.d.ts +3 -3
- package/dist/vinylTestUtil/types/ts4.7/mock/track/dash/createMockDashDependencies.d.ts +1 -2
- package/dist/vinylTestUtil/types/ts4.7/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
- package/docs/USAGE.md +82 -31
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidecarTextTrackController.d.ts","sourceRoot":"","sources":["../../../../src/text/SidecarTextTrackController.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"SidecarTextTrackController.d.ts","sourceRoot":"","sources":["../../../../src/text/SidecarTextTrackController.ts"],"names":[],"mappings":"AAKA,OAAO,EAK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,IAAI,MAAM,CAEjC;IAID,OAAO,CAAC,OAAO,CAAQ;IAEvB,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,gBAAgB,CAA6B;IAGrD,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;gBAEf,IAAI,EAAE,8BAA8B;IAmBjE,IAAI,UAAU,IAAI,SAAS,aAAa,EAAE,CAEzC;IAED,IAAI,eAAe,IAAI,aAAa,GAAG,IAAI,CAE1C;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;OAGG;IACH,OAAO,CAAC,SAAS;IASjB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAqBxB,UAAU,IAAI,IAAI;IAKlB,QAAQ,IAAI,IAAI;IAOhB,OAAO,CAAC,SAAS;IAwDjB,OAAO,CAAC,UAAU;IAqBlB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAYnB;;;OAGG;IACH,OAAO,IAAI,IAAI;CASlB"}
|
|
@@ -2,185 +2,191 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { createAbortSlot, createDisposer, equalDeep, EventHostImpl, logError, } from '@amazon/vinyl-util';
|
|
6
6
|
import { loadWebVttCues } from './SidecarTextTrackLoader';
|
|
7
7
|
import { pickPreferredTextTrack } from './pickPreferredTextTrack';
|
|
8
8
|
import { applyVttCueStyle, isVttCue } from './VttCueStyle';
|
|
9
|
+
/**
|
|
10
|
+
* Selects the text track that matches the given options, or null for none.
|
|
11
|
+
*
|
|
12
|
+
* The `enabled` mode gates everything: `'off'` renders nothing (default is
|
|
13
|
+
* `'forced'`). Otherwise an explicit {@link TextTrackSelection.id} wins; else
|
|
14
|
+
* the best language match is chosen among tracks filtered by kind and
|
|
15
|
+
* forced-ness. Forced-ness comes from {@link TextTrackSelection.forced} when
|
|
16
|
+
* set, otherwise from the mode (`'forced'` keeps only forced tracks, `'on'`
|
|
17
|
+
* only full tracks).
|
|
18
|
+
*
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
export function resolveSelectedTrack(tracks, options) {
|
|
22
|
+
const mode = options.enabled ?? 'forced';
|
|
23
|
+
if (mode === 'off')
|
|
24
|
+
return null;
|
|
25
|
+
const selection = options.selection ?? {};
|
|
26
|
+
if (selection.id != null) {
|
|
27
|
+
return tracks.find((t) => t.id === selection.id) ?? null;
|
|
28
|
+
}
|
|
29
|
+
let pool = tracks;
|
|
30
|
+
if (selection.kind != null) {
|
|
31
|
+
pool = pool.filter((t) => t.kind === selection.kind);
|
|
32
|
+
}
|
|
33
|
+
// Explicit forced filter overrides the mode's forced/full split.
|
|
34
|
+
const forced = selection.forced ?? mode === 'forced';
|
|
35
|
+
pool = pool.filter((t) => t.forced === forced);
|
|
36
|
+
// pickPreferredTextTrack falls back to navigator.languages when no language
|
|
37
|
+
// preference is supplied.
|
|
38
|
+
return pickPreferredTextTrack(pool, selection.language);
|
|
39
|
+
}
|
|
9
40
|
/**
|
|
10
41
|
* Manages a sidecar WebVTT-based text track lifecycle:
|
|
11
42
|
*
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
43
|
+
* - tracks the discovered {@link TextTrackInfo} list (from the `textTracks`
|
|
44
|
+
* observable) and the current selection (from the `options` observable)
|
|
45
|
+
* - on selection, fetches the chosen track's WebVTT and pushes cues to a DOM
|
|
46
|
+
* `TextTrack` obtained from the {@link MediaTextTrackProvider}
|
|
47
|
+
* - clears cues and hides the DOM track when the selection changes or clears
|
|
16
48
|
*
|
|
17
|
-
* The controller is
|
|
18
|
-
*
|
|
19
|
-
* decides to surface.
|
|
49
|
+
* The controller is agnostic of HLS/DASH discovery details; its inputs are the
|
|
50
|
+
* observables supplied by the manifest layer.
|
|
20
51
|
*/
|
|
21
52
|
export class SidecarTextTrackController extends EventHostImpl {
|
|
22
53
|
deps;
|
|
23
54
|
get [Symbol.toStringTag]() {
|
|
24
55
|
return 'SidecarTextTrackController';
|
|
25
56
|
}
|
|
57
|
+
// Whether the owning media track is current (rendering allowed). Toggled by
|
|
58
|
+
// activate()/deactivate() across suspensions such as ad breaks.
|
|
59
|
+
_active = false;
|
|
26
60
|
_tracks = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
preferredLanguageSub;
|
|
61
|
+
_activeTextTrack = null;
|
|
62
|
+
// The DOM text track currently rendering cues, or null when hidden. Owned by
|
|
63
|
+
// the provider (never created/removed here).
|
|
64
|
+
_ref = null;
|
|
65
|
+
loadAbort = createAbortSlot();
|
|
66
|
+
disposer = createDisposer();
|
|
34
67
|
constructor(deps) {
|
|
35
68
|
super();
|
|
36
69
|
this.deps = deps;
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
70
|
+
const { add } = this.disposer;
|
|
71
|
+
// Both fire immediately with the current value, resolving the initial
|
|
72
|
+
// track list and selection on construction.
|
|
73
|
+
add(deps.options.onData(() => this.refreshSelection()));
|
|
74
|
+
add(deps.textTracks.onData((tracksPromise) => {
|
|
75
|
+
tracksPromise
|
|
76
|
+
.then((tracks) => this.setTracks(tracks))
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
// Manifest errors surface through the manifest
|
|
79
|
+
// controller; just note and don't double-report.
|
|
80
|
+
logError(this, 'text tracks promise rejected', error);
|
|
81
|
+
});
|
|
82
|
+
}));
|
|
42
83
|
}
|
|
43
84
|
get textTracks() {
|
|
44
85
|
return this._tracks;
|
|
45
86
|
}
|
|
46
87
|
get activeTextTrack() {
|
|
88
|
+
return this._activeTextTrack;
|
|
89
|
+
}
|
|
90
|
+
get active() {
|
|
47
91
|
return this._active;
|
|
48
92
|
}
|
|
93
|
+
get disposed() {
|
|
94
|
+
return this.disposer.disposed;
|
|
95
|
+
}
|
|
49
96
|
/**
|
|
50
|
-
* Replaces the discovered
|
|
51
|
-
* the
|
|
52
|
-
* selection and emits `activeTextTrackChange`.
|
|
97
|
+
* Replaces the discovered track list, emits `textTracksChange`, then
|
|
98
|
+
* re-applies the current selection against the new list.
|
|
53
99
|
*/
|
|
54
|
-
|
|
55
|
-
if (
|
|
100
|
+
setTracks(tracks) {
|
|
101
|
+
if (this.disposed)
|
|
56
102
|
return;
|
|
57
103
|
const previous = this._tracks;
|
|
104
|
+
if (equalDeep(previous, tracks))
|
|
105
|
+
return;
|
|
58
106
|
this._tracks = tracks;
|
|
59
107
|
this.dispatch('textTracksChange', { previous, current: tracks });
|
|
60
|
-
|
|
61
|
-
// Clear a now-absent selection, but keep _userSelected intact.
|
|
62
|
-
this.selectById(null);
|
|
63
|
-
}
|
|
64
|
-
// A preferred language re-selects the best match as the list changes;
|
|
65
|
-
// otherwise auto-show forced captions until the app makes an explicit
|
|
66
|
-
// choice.
|
|
67
|
-
const preferred = this.deps.preferredTextLanguage?.value;
|
|
68
|
-
if (preferred != null) {
|
|
69
|
-
this.applyPreferredLanguage(preferred);
|
|
70
|
-
}
|
|
71
|
-
else if (!this._userSelected && !this._active) {
|
|
72
|
-
const forced = this.pickForcedTrack(tracks);
|
|
73
|
-
if (forced)
|
|
74
|
-
this.selectById(forced.id);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
setActiveTextTrack(id) {
|
|
78
|
-
// An explicit app choice; stop auto-selecting forced tracks.
|
|
79
|
-
this._userSelected = true;
|
|
80
|
-
this.selectById(id);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Selects the track best matching the preferred language(s), or clears the
|
|
84
|
-
* selection when the preference is null or nothing matches.
|
|
85
|
-
*/
|
|
86
|
-
applyPreferredLanguage(preferred) {
|
|
87
|
-
const target = pickPreferredTextTrack(this._tracks, preferred);
|
|
88
|
-
this.setActiveTextTrack(target?.id ?? null);
|
|
108
|
+
this.refreshSelection();
|
|
89
109
|
}
|
|
90
110
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
111
|
+
* Recomputes the selection from the current options and track list,
|
|
112
|
+
* emitting `activeTextTrackChange` on change and (re)rendering when active.
|
|
93
113
|
*/
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
refreshSelection() {
|
|
115
|
+
const previous = this._activeTextTrack;
|
|
116
|
+
const target = resolveSelectedTrack(this._tracks, this.deps.options.value);
|
|
117
|
+
const trackChanged = target?.id !== previous?.id;
|
|
118
|
+
if (trackChanged) {
|
|
119
|
+
this._activeTextTrack = target;
|
|
120
|
+
this.dispatch('activeTextTrackChange', {
|
|
121
|
+
previous,
|
|
122
|
+
current: target,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!this._active)
|
|
100
126
|
return;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.dispatch('activeTextTrackChange', {
|
|
107
|
-
previous,
|
|
108
|
-
current: target,
|
|
109
|
-
});
|
|
110
|
-
if (target)
|
|
127
|
+
// Cues carry their own authored styling, so only a track change (not a
|
|
128
|
+
// same-track options change) needs a (re)load.
|
|
129
|
+
if (!target)
|
|
130
|
+
this.hideCurrent();
|
|
131
|
+
else if (trackChanged || !this._ref)
|
|
111
132
|
this.startLoad(target);
|
|
112
133
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*/
|
|
117
|
-
pickForcedTrack(tracks) {
|
|
118
|
-
const forced = tracks.filter((t) => t.forced);
|
|
119
|
-
if (forced.length === 0)
|
|
120
|
-
return null;
|
|
121
|
-
const defaultLang = tracks.find((t) => t.default)?.language;
|
|
122
|
-
if (defaultLang != null) {
|
|
123
|
-
const match = forced.find((t) => t.language === defaultLang);
|
|
124
|
-
if (match)
|
|
125
|
-
return match;
|
|
126
|
-
}
|
|
127
|
-
return forced[0];
|
|
128
|
-
}
|
|
129
|
-
suspend() {
|
|
130
|
-
this.loadAbort?.abort();
|
|
131
|
-
this.loadAbort = null;
|
|
132
|
-
this.clearDomTrack();
|
|
133
|
-
}
|
|
134
|
-
resume() {
|
|
135
|
-
// Rebuild only when an active selection exists and it isn't already
|
|
136
|
-
// rendering (clearDomTrack/suspend nulls _domTrack; setActiveTextTrack
|
|
137
|
-
// sets it).
|
|
138
|
-
if (!this._active || this._domTrack)
|
|
139
|
-
return;
|
|
140
|
-
this.startLoad(this._active);
|
|
134
|
+
deactivate() {
|
|
135
|
+
this._active = false;
|
|
136
|
+
this.hideCurrent();
|
|
141
137
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.preferredLanguageSub?.();
|
|
149
|
-
this.loadAbort?.abort();
|
|
150
|
-
this.loadAbort = null;
|
|
151
|
-
this.clearDomTrack();
|
|
152
|
-
this._tracks = [];
|
|
153
|
-
this._active = null;
|
|
138
|
+
activate() {
|
|
139
|
+
this._active = true;
|
|
140
|
+
// Rebuild only when a selection exists and it isn't already rendering.
|
|
141
|
+
if (!this._activeTextTrack || this._ref)
|
|
142
|
+
return;
|
|
143
|
+
this.startLoad(this._activeTextTrack);
|
|
154
144
|
}
|
|
155
145
|
startLoad(track) {
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
const
|
|
146
|
+
// Hide the previously-rendering track (a different rendition) so its
|
|
147
|
+
// cues don't linger alongside the new one; this also aborts any prior
|
|
148
|
+
// in-flight load and arms a fresh abort for this one.
|
|
149
|
+
this.hideCurrent();
|
|
150
|
+
const abort = this.loadAbort.value;
|
|
151
|
+
const ref = this.deps.textTrackProvider.getOrCreate(track.kind, track.label, track.language ?? undefined);
|
|
152
|
+
// With an injected renderer the browser must not paint (the renderer
|
|
153
|
+
// does), but the track still needs to be active for cue timing — hence
|
|
154
|
+
// 'hidden'. Without one, 'showing' uses native rendering. Set the mode
|
|
155
|
+
// before clearing: `cues` reads null while disabled.
|
|
156
|
+
const renderer = this.deps.textTrackRenderer;
|
|
157
|
+
ref.track.mode = renderer ? 'hidden' : 'showing';
|
|
158
|
+
ref.clear();
|
|
159
|
+
this._ref = ref;
|
|
160
|
+
renderer?.setTextTrack(ref.track);
|
|
167
161
|
const CueCtor = getVttCueConstructor();
|
|
168
|
-
// Adjacent HLS caption segments commonly repeat the boundary cue in
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// active load so we don't push the same cue twice.
|
|
162
|
+
// Adjacent HLS caption segments commonly repeat the boundary cue in both
|
|
163
|
+
// segments (so a client that only fetches one still renders the overlap).
|
|
164
|
+
// Track seen keys per active load so we don't push the same cue twice.
|
|
172
165
|
const seen = new Set();
|
|
166
|
+
// Accumulate authored STYLE-block CSS and forward it to the renderer as
|
|
167
|
+
// it arrives — only wired when the renderer can actually consume styles.
|
|
168
|
+
const styles = new Set();
|
|
169
|
+
const setStyles = renderer?.setStyles?.bind(renderer);
|
|
173
170
|
loadWebVttCues(track.uri, {
|
|
174
171
|
abort,
|
|
175
172
|
requestInit: this.deps.requestInit,
|
|
176
173
|
variables: track.variables,
|
|
177
|
-
getCurrentTime: () =>
|
|
174
|
+
getCurrentTime: () => this.deps.playbackController.currentTime,
|
|
178
175
|
onCues: (cues) => {
|
|
179
176
|
if (abort.aborted())
|
|
180
177
|
return;
|
|
181
178
|
if (CueCtor)
|
|
182
|
-
this.appendCues(
|
|
179
|
+
this.appendCues(ref.track, CueCtor, cues, seen);
|
|
183
180
|
},
|
|
181
|
+
onStyles: setStyles
|
|
182
|
+
? (blocks) => {
|
|
183
|
+
if (abort.aborted())
|
|
184
|
+
return;
|
|
185
|
+
for (const block of blocks)
|
|
186
|
+
styles.add(block);
|
|
187
|
+
setStyles([...styles]);
|
|
188
|
+
}
|
|
189
|
+
: undefined,
|
|
184
190
|
}).catch((error) => {
|
|
185
191
|
if (abort.aborted())
|
|
186
192
|
return;
|
|
@@ -190,12 +196,6 @@ export class SidecarTextTrackController extends EventHostImpl {
|
|
|
190
196
|
});
|
|
191
197
|
});
|
|
192
198
|
}
|
|
193
|
-
ensureDomTrack(media, track) {
|
|
194
|
-
const dom = media.addTextTrack(track.kind, track.label, track.language ?? undefined);
|
|
195
|
-
dom.mode = 'showing';
|
|
196
|
-
this._domTrack = dom;
|
|
197
|
-
return dom;
|
|
198
|
-
}
|
|
199
199
|
appendCues(dom, CueCtor, cues, seen) {
|
|
200
200
|
for (const cue of cues) {
|
|
201
201
|
const key = `${cue.startTime}|${cue.endTime}|${cue.text}`;
|
|
@@ -205,30 +205,43 @@ export class SidecarTextTrackController extends EventHostImpl {
|
|
|
205
205
|
const domCue = new CueCtor(cue.startTime, cue.endTime, cue.text);
|
|
206
206
|
if (cue.id != null)
|
|
207
207
|
domCue.id = cue.id;
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (cueStyle && isVttCue(domCue)) {
|
|
213
|
-
applyVttCueStyle(domCue, cueStyle);
|
|
208
|
+
// Preserve the cue's own authored WebVTT settings (position, line,
|
|
209
|
+
// size, align, …). Only VTTCues carry these properties.
|
|
210
|
+
if (cue.settings && isVttCue(domCue)) {
|
|
211
|
+
applyVttCueStyle(domCue, cue.settings);
|
|
214
212
|
}
|
|
215
213
|
dom.addCue(domCue);
|
|
216
214
|
}
|
|
217
215
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Clears cues from the current DOM track and hides it, keeping the track for
|
|
218
|
+
* later reuse via the provider.
|
|
219
|
+
*/
|
|
220
|
+
hideCurrent() {
|
|
221
|
+
// Cancel any in-flight load: its cues are no longer wanted, and a late
|
|
222
|
+
// rejection must not surface as a textTrackError.
|
|
223
|
+
this.loadAbort.abort();
|
|
224
|
+
const ref = this._ref;
|
|
225
|
+
if (!ref)
|
|
221
226
|
return;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
227
|
+
this.deps.textTrackRenderer?.setTextTrack(null);
|
|
228
|
+
ref.clear();
|
|
229
|
+
ref.track.mode = 'disabled';
|
|
230
|
+
this._ref = null;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Cancels any in-flight load, hides the DOM text track, and resets state.
|
|
234
|
+
* Called by the host when the underlying media is unloaded.
|
|
235
|
+
*/
|
|
236
|
+
dispose() {
|
|
237
|
+
if (this.disposed)
|
|
238
|
+
return;
|
|
239
|
+
super.dispose();
|
|
240
|
+
this.loadAbort.abort();
|
|
241
|
+
this.hideCurrent();
|
|
242
|
+
this.disposer.dispose();
|
|
243
|
+
this._tracks = [];
|
|
244
|
+
this._activeTextTrack = null;
|
|
232
245
|
}
|
|
233
246
|
}
|
|
234
247
|
function getVttCueConstructor() {
|
|
@@ -24,6 +24,11 @@ export interface LoadWebVttCuesOptions {
|
|
|
24
24
|
* per HLS segment, or once for a direct `.vtt` document.
|
|
25
25
|
*/
|
|
26
26
|
readonly onCues: (cues: readonly WebVttCue[]) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Invoked with the CSS body of any `STYLE` blocks parsed from a document.
|
|
29
|
+
* Only called when a document actually declares styles.
|
|
30
|
+
*/
|
|
31
|
+
readonly onStyles?: Maybe<(styles: readonly string[]) => void>;
|
|
27
32
|
/**
|
|
28
33
|
* Returns the current playback time (seconds on the presentation
|
|
29
34
|
* timeline). Used to fetch caption segments in a window around the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidecarTextTrackLoader.d.ts","sourceRoot":"","sources":["../../../../src/text/SidecarTextTrackLoader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,KAAK,EACL,aAAa,EACb,kBAAkB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AAE3D;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAA;AAQzC,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;IAEhD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAE5D;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,KAAK,IAAI,CAAA;IAErD;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,MAAM,CAAA;IAErC;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAElC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CACtC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,qBAAqB,GAC/B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"SidecarTextTrackLoader.d.ts","sourceRoot":"","sources":["../../../../src/text/SidecarTextTrackLoader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,KAAK,EACL,aAAa,EACb,kBAAkB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,eAAe,CAAA;AAE3D;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAA;AAQzC,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;IAEhD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAE5D;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,KAAK,IAAI,CAAA;IAErD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC,CAAA;IAE9D;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,MAAM,CAAA;IAErC;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAElC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CACtC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,qBAAqB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA0Cf"}
|
|
@@ -39,7 +39,7 @@ const IDLE_POLL_SECONDS = 0.25;
|
|
|
39
39
|
* abort signal fires. Fetch failures reject the promise.
|
|
40
40
|
*/
|
|
41
41
|
export async function loadWebVttCues(uri, options) {
|
|
42
|
-
const { abort, requestInit, variables, onCues, getCurrentTime } = options;
|
|
42
|
+
const { abort, requestInit, variables, onCues, onStyles, getCurrentTime } = options;
|
|
43
43
|
const lookAhead = options.lookAhead ?? DEFAULT_TEXT_LOOK_AHEAD;
|
|
44
44
|
const lookBehind = options.lookBehind ?? DEFAULT_TEXT_LOOK_BEHIND;
|
|
45
45
|
const init = requestInit ?? undefined;
|
|
@@ -50,6 +50,7 @@ export async function loadWebVttCues(uri, options) {
|
|
|
50
50
|
abort,
|
|
51
51
|
variables: variables ?? undefined,
|
|
52
52
|
onCues,
|
|
53
|
+
onStyles,
|
|
53
54
|
getCurrentTime,
|
|
54
55
|
lookAhead,
|
|
55
56
|
lookBehind,
|
|
@@ -66,14 +67,17 @@ export async function loadWebVttCues(uri, options) {
|
|
|
66
67
|
abort,
|
|
67
68
|
variables: variables ?? undefined,
|
|
68
69
|
onCues,
|
|
70
|
+
onStyles,
|
|
69
71
|
getCurrentTime,
|
|
70
72
|
lookAhead,
|
|
71
73
|
lookBehind,
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
|
-
const
|
|
75
|
-
if (cues.length > 0)
|
|
76
|
-
onCues(cues);
|
|
76
|
+
const doc = parseWebVtt(body);
|
|
77
|
+
if (doc.cues.length > 0)
|
|
78
|
+
onCues(doc.cues);
|
|
79
|
+
if (onStyles && doc.styles.length > 0)
|
|
80
|
+
onStyles(doc.styles);
|
|
77
81
|
}
|
|
78
82
|
function looksLikeMediaPlaylist(uri) {
|
|
79
83
|
const path = uri.split(/[?#]/)[0];
|
|
@@ -113,9 +117,11 @@ async function streamMediaPlaylistText(ctx) {
|
|
|
113
117
|
abort: ctx.abort,
|
|
114
118
|
});
|
|
115
119
|
const body = await res.text();
|
|
116
|
-
const
|
|
117
|
-
if (cues.length > 0)
|
|
118
|
-
ctx.onCues(cues);
|
|
120
|
+
const doc = parseWebVtt(body);
|
|
121
|
+
if (doc.cues.length > 0)
|
|
122
|
+
ctx.onCues(doc.cues);
|
|
123
|
+
if (ctx.onStyles && doc.styles.length > 0)
|
|
124
|
+
ctx.onStyles(doc.styles);
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChangeEvent } from '../event/ChangeEvent';
|
|
2
2
|
import type { ReadonlyEventHost } from '@amazon/vinyl-util';
|
|
3
|
+
import type { ObjectSchema } from '@amazon/vinyl-validation';
|
|
3
4
|
/**
|
|
4
5
|
* Categorizes the role of a text track. Mirrors HTMLMediaElement.TextTrackKind.
|
|
5
6
|
*/
|
|
@@ -79,6 +80,64 @@ export interface TextTrackErrorEvent {
|
|
|
79
80
|
readonly track: TextTrackInfo;
|
|
80
81
|
readonly error: Error;
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Which captions render:
|
|
85
|
+
* - `'off'` — nothing renders (not even forced narrative captions).
|
|
86
|
+
* - `'forced'` — only forced (narrative) tracks, so nothing shows unless the
|
|
87
|
+
* content carries a forced track for the preferred language.
|
|
88
|
+
* - `'on'` — the full (non-forced) subtitle track for the preferred language.
|
|
89
|
+
*/
|
|
90
|
+
export type CaptionMode = 'on' | 'off' | 'forced';
|
|
91
|
+
/**
|
|
92
|
+
* Criteria used to pick which text track to render. Applied in priority order:
|
|
93
|
+
* an explicit {@link id} wins; otherwise the best {@link language} match is
|
|
94
|
+
* chosen among tracks filtered by {@link kind} and by forced-ness (from
|
|
95
|
+
* {@link forced} when set, else from the controller's
|
|
96
|
+
* {@link TextTrackControllerOptions.enabled} mode).
|
|
97
|
+
*/
|
|
98
|
+
export interface TextTrackSelection {
|
|
99
|
+
/**
|
|
100
|
+
* Selects the text track with this exact identifier, ignoring the other
|
|
101
|
+
* criteria (but still gated by the `'off'` mode). If no track has this id,
|
|
102
|
+
* nothing is selected.
|
|
103
|
+
*/
|
|
104
|
+
readonly id?: string | null;
|
|
105
|
+
/**
|
|
106
|
+
* Restricts selection to tracks of this kind (e.g. `'captions'`). Unset
|
|
107
|
+
* considers all kinds.
|
|
108
|
+
*/
|
|
109
|
+
readonly kind?: TextTrackKind | null;
|
|
110
|
+
/**
|
|
111
|
+
* Preferred caption language(s), most-preferred first, as RFC 5646 tags.
|
|
112
|
+
* When unset (or empty) selection falls back to the platform's
|
|
113
|
+
* `navigator.languages`.
|
|
114
|
+
*/
|
|
115
|
+
readonly language?: string | readonly string[] | null;
|
|
116
|
+
/**
|
|
117
|
+
* Explicit forced-ness filter. When set, only tracks whose `forced` flag
|
|
118
|
+
* equals this value are considered, overriding the forced/full split
|
|
119
|
+
* implied by the `enabled` mode. Unset means the mode decides.
|
|
120
|
+
*/
|
|
121
|
+
readonly forced?: boolean | null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Declarative configuration for a {@link TextTrackController}. Rendering is
|
|
125
|
+
* driven entirely by this value (via `VinylOptions.text`); there is no
|
|
126
|
+
* imperative track-select call.
|
|
127
|
+
*/
|
|
128
|
+
export interface TextTrackControllerOptions {
|
|
129
|
+
/**
|
|
130
|
+
* Which captions render (see {@link CaptionMode}). Unset defaults to
|
|
131
|
+
* `'forced'`.
|
|
132
|
+
*/
|
|
133
|
+
readonly enabled?: CaptionMode | null;
|
|
134
|
+
/**
|
|
135
|
+
* The selection criteria (language / id / kind). When unset, the preferred
|
|
136
|
+
* languages fall back to the platform's `navigator.languages`.
|
|
137
|
+
*/
|
|
138
|
+
readonly selection?: TextTrackSelection | null;
|
|
139
|
+
}
|
|
140
|
+
export declare const textTrackControllerOptionsValidator: ObjectSchema<TextTrackControllerOptions>;
|
|
82
141
|
export declare const ALL_TEXT_TRACK_EVENTS: readonly ["textTracksChange", "activeTextTrackChange", "textTrackError"];
|
|
83
142
|
/**
|
|
84
143
|
* Read-only view of available text tracks and the active selection.
|
|
@@ -92,34 +151,29 @@ export interface ReadonlyTextTrackController extends ReadonlyEventHost<TextTrack
|
|
|
92
151
|
* The currently active text track, or null if none is active.
|
|
93
152
|
*/
|
|
94
153
|
readonly activeTextTrack: TextTrackInfo | null;
|
|
154
|
+
/**
|
|
155
|
+
* Returns true if this text track controller is active.
|
|
156
|
+
*/
|
|
157
|
+
get active(): boolean;
|
|
95
158
|
}
|
|
96
159
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* Selection is persisted across track changes only when applications choose
|
|
101
|
-
* to call {@link setActiveTextTrack} again on the new track. This matches
|
|
102
|
-
* how audio tracks are typically driven.
|
|
160
|
+
* Full controller for the current media's text tracks. Selection is driven
|
|
161
|
+
* declaratively through the controller's options (`VinylOptions.text`); this
|
|
162
|
+
* interface only adds the render lifecycle used by the owning media track.
|
|
103
163
|
*/
|
|
104
164
|
export interface TextTrackController extends ReadonlyTextTrackController {
|
|
105
|
-
/**
|
|
106
|
-
* Selects the text track with the given id, or clears the active text
|
|
107
|
-
* track when called with null. No-op if the id does not match a known
|
|
108
|
-
* text track.
|
|
109
|
-
*/
|
|
110
|
-
setActiveTextTrack(id: string | null): void;
|
|
111
165
|
/**
|
|
112
166
|
* Suspends cue rendering without changing the active selection: cancels any
|
|
113
|
-
* in-flight load and
|
|
114
|
-
*
|
|
115
|
-
*
|
|
167
|
+
* in-flight load and hides the DOM text track (so its cues stop showing).
|
|
168
|
+
* Called when the owning media track is deactivated — e.g. while an ad
|
|
169
|
+
* plays over the suspended content. {@link activate} rebuilds it.
|
|
116
170
|
*/
|
|
117
|
-
|
|
171
|
+
deactivate(): void;
|
|
118
172
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
173
|
+
* Resumes rendering the active selection after a {@link deactivate},
|
|
174
|
+
* reloading its cues. No-op when nothing is selected or already rendering.
|
|
175
|
+
* Called when the owning media track is reactivated.
|
|
122
176
|
*/
|
|
123
|
-
|
|
177
|
+
activate(): void;
|
|
124
178
|
}
|
|
125
179
|
//# sourceMappingURL=TextTrack.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextTrack.d.ts","sourceRoot":"","sources":["../../../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;IACrF;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAA;IAE7C;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,aAAa,GAAG,IAAI,CAAA;IAE9C;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,2BAA2B;IACpE;;;;;OAKG;IACH,UAAU,IAAI,IAAI,CAAA;IAElB;;;;OAIG;IACH,QAAQ,IAAI,IAAI,CAAA;CACnB"}
|
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
+
import { array, boolean, isOneOf, object, string, } from '@amazon/vinyl-validation';
|
|
6
|
+
const TEXT_TRACK_KINDS = [
|
|
7
|
+
'subtitles',
|
|
8
|
+
'captions',
|
|
9
|
+
'descriptions',
|
|
10
|
+
'chapters',
|
|
11
|
+
'metadata',
|
|
12
|
+
];
|
|
13
|
+
const textTrackSelectionValidator = object({
|
|
14
|
+
id: string().orNull().optional(),
|
|
15
|
+
kind: isOneOf(...TEXT_TRACK_KINDS)
|
|
16
|
+
.orNull()
|
|
17
|
+
.optional(),
|
|
18
|
+
language: string().or(array(string()).readonly()).orNull().optional(),
|
|
19
|
+
forced: boolean().orNull().optional(),
|
|
20
|
+
});
|
|
21
|
+
export const textTrackControllerOptionsValidator = object({
|
|
22
|
+
enabled: isOneOf('on', 'off', 'forced').orNull().optional(),
|
|
23
|
+
selection: textTrackSelectionValidator.orNull().optional(),
|
|
24
|
+
});
|
|
5
25
|
export const ALL_TEXT_TRACK_EVENTS = [
|
|
6
26
|
'textTracksChange',
|
|
7
27
|
'activeTextTrackChange',
|