@supr-design/flux-player 0.0.0-stage → 1.2.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/Apache-2.0.txt +55 -0
- package/LICENSE +131 -0
- package/LICENSE.txt +131 -0
- package/README.md +38 -2
- package/autoInit.d.ts +6 -0
- package/createPlayer.d.ts +2 -0
- package/dash.all.min-BICTfaEX.js +38600 -0
- package/dash.all.min.js.LICENSE.txt +12 -0
- package/flux-player.es.js +1930 -0
- package/flux-player.umd.js +59 -0
- package/hls-Db1HP87O.js +18448 -0
- package/index.d.ts +9 -0
- package/package.json +16 -4
- package/src-BTcoslE8.js +404 -0
- package/src-DMaUVQqo.js +439 -0
- package/styles.css +513 -0
- package/third-party-licenses.txt +50 -0
- package/types.d.ts +285 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPlayer } from './createPlayer.js';
|
|
2
|
+
import { autoInitFluxPlayers } from './autoInit.js';
|
|
3
|
+
declare const Flux: {
|
|
4
|
+
createPlayer: typeof createPlayer;
|
|
5
|
+
autoInitFluxPlayers: (options?: import('./autoInit.js').FluxAutoInitOptions) => import('./types.js').PlayerInstance[];
|
|
6
|
+
};
|
|
7
|
+
export { createPlayer, autoInitFluxPlayers, Flux };
|
|
8
|
+
export type * from './types.js';
|
|
9
|
+
export type { FluxAutoInitOptions } from './autoInit.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supr-design/flux-player",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Web video player with HLS, MPEG-DASH, native playback and customizable controls",
|
|
5
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./flux-player.es.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": { "types": "./index.d.ts", "import": "./flux-player.es.js" },
|
|
11
|
+
"./styles.css": "./styles.css",
|
|
12
|
+
"./flux-player.umd.js": "./flux-player.umd.js"
|
|
13
|
+
},
|
|
14
|
+
"files": ["*.js", "*.d.ts", "*.css", "*.txt"],
|
|
15
|
+
"homepage": "https://supr-design.github.io/Flux/",
|
|
16
|
+
"repository": { "type": "git", "url": "git+https://github.com/Supr-Design/Flux.git" },
|
|
17
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" }
|
|
18
|
+
}
|
package/src-BTcoslE8.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
//#region packages/engine-dash/dist/src/DashEngine.js
|
|
2
|
+
var e = class {
|
|
3
|
+
id = "dash";
|
|
4
|
+
isNative = !1;
|
|
5
|
+
video = null;
|
|
6
|
+
player = null;
|
|
7
|
+
dashjs = null;
|
|
8
|
+
loadVersion = 0;
|
|
9
|
+
cancelPendingLoad;
|
|
10
|
+
lastSource = null;
|
|
11
|
+
retryCount = 0;
|
|
12
|
+
maxRetries = 2;
|
|
13
|
+
runtimeConfig = {
|
|
14
|
+
performance: {
|
|
15
|
+
startupMode: "balanced",
|
|
16
|
+
startupBufferSeconds: 1.2,
|
|
17
|
+
manifestFastPath: !1
|
|
18
|
+
},
|
|
19
|
+
abr: {
|
|
20
|
+
startupProfile: "balanced",
|
|
21
|
+
upgradeAggression: "medium",
|
|
22
|
+
rebufferSafetyBias: "medium"
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
lastRebufferDowngradeAt = 0;
|
|
26
|
+
listeners = /* @__PURE__ */ new Map();
|
|
27
|
+
domListeners = [];
|
|
28
|
+
setRuntimeConfig(e) {
|
|
29
|
+
this.runtimeConfig = {
|
|
30
|
+
performance: {
|
|
31
|
+
startupMode: e.performance?.startupMode ?? this.runtimeConfig.performance.startupMode,
|
|
32
|
+
startupBufferSeconds: e.performance?.startupBufferSeconds ?? this.runtimeConfig.performance.startupBufferSeconds,
|
|
33
|
+
manifestFastPath: e.performance?.manifestFastPath ?? this.runtimeConfig.performance.manifestFastPath
|
|
34
|
+
},
|
|
35
|
+
abr: {
|
|
36
|
+
startupProfile: e.abr?.startupProfile ?? this.runtimeConfig.abr.startupProfile,
|
|
37
|
+
upgradeAggression: e.abr?.upgradeAggression ?? this.runtimeConfig.abr.upgradeAggression,
|
|
38
|
+
rebufferSafetyBias: e.abr?.rebufferSafetyBias ?? this.runtimeConfig.abr.rebufferSafetyBias
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
canPlayType(e) {
|
|
43
|
+
return e === "dash";
|
|
44
|
+
}
|
|
45
|
+
canPlaySource(e) {
|
|
46
|
+
return e.toLowerCase().includes(".mpd");
|
|
47
|
+
}
|
|
48
|
+
async preload() {
|
|
49
|
+
await this.ensureDashJs();
|
|
50
|
+
}
|
|
51
|
+
async ensureDashJs() {
|
|
52
|
+
return this.dashjs ||= await import("./dash.all.min-BICTfaEX.js"), this.dashjs;
|
|
53
|
+
}
|
|
54
|
+
attach(e) {
|
|
55
|
+
this.video = e, this.bindDomEvents(), this.player && this.player.attachView(e);
|
|
56
|
+
}
|
|
57
|
+
bindDomEvents() {
|
|
58
|
+
if (!this.video) return;
|
|
59
|
+
this.unbindDomEvents();
|
|
60
|
+
let e = (e, t, n = () => void 0) => {
|
|
61
|
+
let r = (r) => {
|
|
62
|
+
let i = n(r);
|
|
63
|
+
e === "waiting" && this.rebufferAwareDowngrade(), this.emit(t, i);
|
|
64
|
+
};
|
|
65
|
+
this.video.addEventListener(e, r), this.domListeners.push({
|
|
66
|
+
event: e,
|
|
67
|
+
handler: r
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
e("play", "play"), e("pause", "pause"), e("playing", "playing"), e("ended", "ended"), e("waiting", "waiting"), e("seeked", "seeked", () => ({ currentTime: this.video.currentTime })), e("canplay", "ready"), e("timeupdate", "timeupdate", () => ({ currentTime: this.video.currentTime })), e("durationchange", "durationchange", () => ({
|
|
71
|
+
duration: this.video.duration,
|
|
72
|
+
isLive: this.player?.isDynamic?.()
|
|
73
|
+
})), e("volumechange", "volumechange", () => ({
|
|
74
|
+
volume: this.video.volume,
|
|
75
|
+
muted: this.video.muted
|
|
76
|
+
})), e("ratechange", "ratechange", () => ({ playbackRate: this.video.playbackRate })), e("progress", "progress", () => {
|
|
77
|
+
let e = [], t = this.video.buffered;
|
|
78
|
+
for (let n = 0; n < t.length; n++) e.push({
|
|
79
|
+
start: t.start(n),
|
|
80
|
+
end: t.end(n)
|
|
81
|
+
});
|
|
82
|
+
return { buffered: e };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
unbindDomEvents() {
|
|
86
|
+
this.video && (this.domListeners.forEach(({ event: e, handler: t }) => {
|
|
87
|
+
this.video.removeEventListener(e, t);
|
|
88
|
+
}), this.domListeners = []);
|
|
89
|
+
}
|
|
90
|
+
async load(e) {
|
|
91
|
+
if (!this.video) throw Error("Video element not attached");
|
|
92
|
+
this.video.poster = e.poster || "";
|
|
93
|
+
let t = ++this.loadVersion;
|
|
94
|
+
this.lastSource = e, this.retryCount = 0;
|
|
95
|
+
let n = await this.ensureDashJs();
|
|
96
|
+
if (t !== this.loadVersion) return;
|
|
97
|
+
this.player && this.player.destroy(), this.player = n.MediaPlayer().create(), this.emit("telemetry", {
|
|
98
|
+
name: "manifest_parse_started",
|
|
99
|
+
at: Date.now()
|
|
100
|
+
});
|
|
101
|
+
let r = this.runtimeConfig.abr.startupProfile, i = this.runtimeConfig.performance.startupMode, a = this.runtimeConfig.performance.manifestFastPath || i === "fast-first-frame";
|
|
102
|
+
e.drm && this.player.setProtectionData(e.drm);
|
|
103
|
+
let o = r === "fast" ? 350 : r === "quality" ? 1400 : 800;
|
|
104
|
+
this.player.updateSettings({ streaming: {
|
|
105
|
+
buffer: {
|
|
106
|
+
fastSwitchEnabled: a,
|
|
107
|
+
bufferTimeDefault: a ? 4 : 12
|
|
108
|
+
},
|
|
109
|
+
trackSwitchMode: {
|
|
110
|
+
audio: "alwaysReplace",
|
|
111
|
+
video: "neverReplace"
|
|
112
|
+
},
|
|
113
|
+
cacheInitSegments: a,
|
|
114
|
+
scheduling: { scheduleWhilePaused: !0 },
|
|
115
|
+
abr: {
|
|
116
|
+
autoSwitchBitrate: { video: !0 },
|
|
117
|
+
initialBitrate: { video: o }
|
|
118
|
+
},
|
|
119
|
+
text: { defaultEnabled: !a }
|
|
120
|
+
} }), this.registerTrackSyncEvents(), this.player.on(n.MediaPlayer.events.QUALITY_CHANGE_RENDERED, (e) => {
|
|
121
|
+
if (e.mediaType === "video") {
|
|
122
|
+
let e = this.player.getSettings().streaming?.abr?.autoSwitchBitrate?.video;
|
|
123
|
+
this.emit("qualitychange", { level: e ? "auto" : this.currentQualityIndex() }), this.syncTracks();
|
|
124
|
+
}
|
|
125
|
+
}), this.player.on(n.MediaPlayer.events.TRACK_CHANGE_RENDERED, () => {
|
|
126
|
+
this.syncTracks();
|
|
127
|
+
}), await new Promise((t, r) => {
|
|
128
|
+
this.cancelPendingLoad = () => r(new DOMException("Load superseded", "AbortError"));
|
|
129
|
+
let i = !1, a = () => {
|
|
130
|
+
this.player && (this.player.off(n.MediaPlayer.events.STREAM_INITIALIZED, o), this.player.off(n.MediaPlayer.events.PLAYBACK_METADATA_LOADED, o), this.player.off(n.MediaPlayer.events.ERROR, s));
|
|
131
|
+
}, o = () => {
|
|
132
|
+
i || (i = !0, this.emit("telemetry", {
|
|
133
|
+
name: "manifest_parse_completed",
|
|
134
|
+
at: Date.now()
|
|
135
|
+
}), this.emit("telemetry", {
|
|
136
|
+
name: "first_append_completed",
|
|
137
|
+
at: Date.now()
|
|
138
|
+
}), this.syncTracks(), a(), this.cancelPendingLoad = void 0, t());
|
|
139
|
+
}, s = (e) => {
|
|
140
|
+
let t = e?.error?.code || "UNKNOWN", n = String(e?.error?.message || "Dash error"), o = n.toLowerCase();
|
|
141
|
+
if ((o.includes("manifest") || o.includes("segment") || o.includes("download")) && this.retryCount < this.maxRetries && this.lastSource) {
|
|
142
|
+
this.retryCount += 1, this.player?.attachSource?.(this.lastSource.src), this.emit("error", { error: {
|
|
143
|
+
code: `DASH_${String(t)}_RETRY`,
|
|
144
|
+
message: `Recovered load failure (${this.retryCount}/${this.maxRetries})`,
|
|
145
|
+
engine: this.id,
|
|
146
|
+
recoverable: !0,
|
|
147
|
+
originalError: e
|
|
148
|
+
} });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.emit("error", { error: {
|
|
152
|
+
code: `DASH_${String(t)}`,
|
|
153
|
+
message: n,
|
|
154
|
+
engine: this.id,
|
|
155
|
+
recoverable: !1,
|
|
156
|
+
originalError: e
|
|
157
|
+
} }), i || (a(), r(Error(e?.error?.message || "Dash load failed")));
|
|
158
|
+
};
|
|
159
|
+
this.player.on(n.MediaPlayer.events.STREAM_INITIALIZED, o), this.player.on(n.MediaPlayer.events.PLAYBACK_METADATA_LOADED, o);
|
|
160
|
+
for (let [e, t] of [
|
|
161
|
+
["MANIFEST_LOADING", "manifest_request_started"],
|
|
162
|
+
["MANIFEST_LOADED", "manifest_received"],
|
|
163
|
+
["FRAGMENT_LOADING_STARTED", "first_segment_request_started"],
|
|
164
|
+
["FRAGMENT_LOADING_COMPLETED", "first_segment_received"]
|
|
165
|
+
]) {
|
|
166
|
+
let r = n.MediaPlayer.events[e];
|
|
167
|
+
r && this.player.on(r, () => {
|
|
168
|
+
this.emit("telemetry", {
|
|
169
|
+
name: t,
|
|
170
|
+
at: Date.now()
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
this.player.on(n.MediaPlayer.events.ERROR, s), this.emit("telemetry", {
|
|
175
|
+
name: "manifest_request_started",
|
|
176
|
+
at: Date.now()
|
|
177
|
+
}), this.player.initialize(this.video, e.src, !1);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
registerTrackSyncEvents() {
|
|
181
|
+
if (!this.player || !this.dashjs) return;
|
|
182
|
+
for (let e of [
|
|
183
|
+
"STREAM_INITIALIZED",
|
|
184
|
+
"PLAYBACK_METADATA_LOADED",
|
|
185
|
+
"CAN_PLAY",
|
|
186
|
+
"PERIOD_SWITCH_COMPLETED",
|
|
187
|
+
"MANIFEST_LOADED",
|
|
188
|
+
"TEXT_TRACKS_ADDED",
|
|
189
|
+
"TEXT_TRACK_ADDED",
|
|
190
|
+
"TRACK_CHANGE_RENDERED"
|
|
191
|
+
]) {
|
|
192
|
+
let t = this.dashjs.MediaPlayer.events[e];
|
|
193
|
+
t && this.player.on(t, () => {
|
|
194
|
+
this.syncTracks();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
let e = this.dashjs.MediaPlayer.events.ERROR;
|
|
198
|
+
e && this.player.on(e, (e) => {
|
|
199
|
+
this.handleDashRuntimeError(e);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
handleDashRuntimeError(e) {
|
|
203
|
+
let t = String(e?.error?.code || "").toLowerCase(), n = String(e?.error?.message || "").toLowerCase(), r = t.includes("buffer_stalled") || t.includes("bufferstalled") || n.includes("buffer stalled"), i = t.includes("manifest") || t.includes("download") || n.includes("segment") || n.includes("manifest"), a = t.includes("media") || n.includes("decode");
|
|
204
|
+
if (r) {
|
|
205
|
+
this.emit("error", { error: {
|
|
206
|
+
code: "DASH_BUFFER_STALL",
|
|
207
|
+
message: "Buffer stall detected",
|
|
208
|
+
engine: this.id,
|
|
209
|
+
recoverable: !0,
|
|
210
|
+
originalError: e
|
|
211
|
+
} });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (i && this.retryCount < this.maxRetries && this.lastSource) {
|
|
215
|
+
this.retryCount += 1, this.player.attachSource?.(this.lastSource.src), this.emit("error", { error: {
|
|
216
|
+
code: "DASH_NETWORK_RETRY",
|
|
217
|
+
message: `Retrying network/segment request (${this.retryCount}/${this.maxRetries})`,
|
|
218
|
+
engine: this.id,
|
|
219
|
+
recoverable: !0,
|
|
220
|
+
originalError: e
|
|
221
|
+
} });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (a) {
|
|
225
|
+
let t = this.currentQualityIndex();
|
|
226
|
+
if (typeof t == "number" && t > 0) {
|
|
227
|
+
this.player.updateSettings({ streaming: { abr: { autoSwitchBitrate: { video: !1 } } } }), this.player.setRepresentationForTypeByIndex?.("video", t - 1), this.emit("error", { error: {
|
|
228
|
+
code: "DASH_DECODE_FALLBACK",
|
|
229
|
+
message: "Decode issue detected, switched to lower quality",
|
|
230
|
+
engine: this.id,
|
|
231
|
+
recoverable: !0,
|
|
232
|
+
originalError: e
|
|
233
|
+
} });
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
currentQualityIndex() {
|
|
239
|
+
let e = this.player?.getCurrentRepresentationForType("video")?.id;
|
|
240
|
+
return this.getQualityLadder().findIndex((t) => t.id === e);
|
|
241
|
+
}
|
|
242
|
+
getQualityLadder() {
|
|
243
|
+
if (!this.player) return [];
|
|
244
|
+
let e = this.player, t = e.getBitrateInfoListFor?.("video");
|
|
245
|
+
if (Array.isArray(t) && t.length > 0) return t;
|
|
246
|
+
let n = e.getRepresentationsByType?.("video");
|
|
247
|
+
return Array.isArray(n) && n.length > 0 ? n.map((e, t) => ({
|
|
248
|
+
qualityIndex: e.qualityIndex ?? t,
|
|
249
|
+
bitrate: e.bandwidth ?? e.bitrate,
|
|
250
|
+
width: e.width,
|
|
251
|
+
height: e.height,
|
|
252
|
+
id: e.id
|
|
253
|
+
})) : [];
|
|
254
|
+
}
|
|
255
|
+
getTracks(e) {
|
|
256
|
+
if (!this.player) return [];
|
|
257
|
+
let t = this.player.getTracksFor?.(e);
|
|
258
|
+
return Array.isArray(t) && t.length > 0 ? t : this.video && e === "text" && this.video.textTracks ? Array.from(this.video.textTracks).map((e, t) => ({
|
|
259
|
+
id: String(t),
|
|
260
|
+
index: t,
|
|
261
|
+
lang: e.language,
|
|
262
|
+
label: e.label,
|
|
263
|
+
kind: e.kind,
|
|
264
|
+
_native: e
|
|
265
|
+
})) : [];
|
|
266
|
+
}
|
|
267
|
+
normalizeTrackLabel(e, t, n) {
|
|
268
|
+
let r = e?.roles?.[0]?.value ?? e?.roles?.[0], i = typeof r == "string" ? " (" + r + ")" : "", a = e?.lang || e?.language || "";
|
|
269
|
+
return `${e?.label || e?.name || a || `${t} ${n + 1}`}${i}`;
|
|
270
|
+
}
|
|
271
|
+
getTrackId(e, t) {
|
|
272
|
+
return String(t);
|
|
273
|
+
}
|
|
274
|
+
enforceSingleNativeTextTrack(e) {
|
|
275
|
+
if (!this.video?.textTracks) return;
|
|
276
|
+
let t = this.video.textTracks;
|
|
277
|
+
for (let n = 0; n < t.length; n += 1) {
|
|
278
|
+
let r = t[n];
|
|
279
|
+
if (e === null) {
|
|
280
|
+
r.mode = "disabled";
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
r.mode = n === e ? "showing" : "disabled";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
matchesTrackId(e, t, n) {
|
|
287
|
+
return this.getTrackId(e, t) === n;
|
|
288
|
+
}
|
|
289
|
+
syncTracks() {
|
|
290
|
+
if (!this.player) return;
|
|
291
|
+
let e = this.getQualityLadder().map((e, t) => {
|
|
292
|
+
let n = e.qualityIndex ?? t, r = e.bandwidth ?? e.bitrate;
|
|
293
|
+
return {
|
|
294
|
+
id: n,
|
|
295
|
+
label: e.height ? `${e.height}p (${Math.round((r || 0) / 1e3)}kbps)` : `Quality ${t + 1} (${Math.round((r || 0) / 1e3)}kbps)`,
|
|
296
|
+
bitrate: r,
|
|
297
|
+
width: e.width,
|
|
298
|
+
height: e.height,
|
|
299
|
+
selected: !this.player.getSettings().streaming?.abr?.autoSwitchBitrate?.video && this.currentQualityIndex() === n
|
|
300
|
+
};
|
|
301
|
+
}), t = this.getTracks("text"), n = /* @__PURE__ */ new Set(), r = t.filter((e) => {
|
|
302
|
+
let t = `${String(e?.lang || e?.language || "")}|${String(e?.label || e?.name || "")}|${String(e?.kind || "")}`;
|
|
303
|
+
return n.has(t) ? !1 : (n.add(t), !0);
|
|
304
|
+
}), i = this.player.getCurrentTrackFor?.("text"), a = r.map((e) => ({
|
|
305
|
+
id: String(t.indexOf(e)),
|
|
306
|
+
label: this.normalizeTrackLabel(e, "Subtitle", t.indexOf(e)),
|
|
307
|
+
language: e.lang || e.language,
|
|
308
|
+
selected: i ? i.index === e.index : e._native?.mode === "showing"
|
|
309
|
+
})), o = this.getTracks("audio"), s = this.player.getCurrentTrackFor?.("audio"), c = o.map((e, t) => ({
|
|
310
|
+
id: this.getTrackId(e, t),
|
|
311
|
+
label: this.normalizeTrackLabel(e, "Audio", t),
|
|
312
|
+
language: e.lang || e.language,
|
|
313
|
+
selected: s ? s.index === e.index : !!e?.selected
|
|
314
|
+
}));
|
|
315
|
+
this.emit("trackschange", {
|
|
316
|
+
qualities: e,
|
|
317
|
+
subtitles: a,
|
|
318
|
+
audioTracks: c
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
rebufferAwareDowngrade() {
|
|
322
|
+
if (!this.player) return;
|
|
323
|
+
let e = Date.now();
|
|
324
|
+
if (e - this.lastRebufferDowngradeAt < 2500 || !this.video || this.video.currentTime < .5) return;
|
|
325
|
+
let t = this.currentQualityIndex();
|
|
326
|
+
if (typeof t != "number" || t <= 0) return;
|
|
327
|
+
let n = this.runtimeConfig.abr.rebufferSafetyBias, r = Math.max(0, t - (n === "high" ? 2 : 1));
|
|
328
|
+
try {
|
|
329
|
+
this.player.setRepresentationForTypeByIndex("video", r), this.lastRebufferDowngradeAt = e, this.emit("telemetry", {
|
|
330
|
+
name: "abr_rebuffer_downgrade",
|
|
331
|
+
at: e,
|
|
332
|
+
data: {
|
|
333
|
+
from: t,
|
|
334
|
+
to: r,
|
|
335
|
+
bias: n
|
|
336
|
+
}
|
|
337
|
+
}), this.syncTracks();
|
|
338
|
+
} catch {}
|
|
339
|
+
}
|
|
340
|
+
async play() {
|
|
341
|
+
await this.video?.play();
|
|
342
|
+
}
|
|
343
|
+
pause() {
|
|
344
|
+
this.video?.pause();
|
|
345
|
+
}
|
|
346
|
+
async destroy() {
|
|
347
|
+
++this.loadVersion, this.cancelPendingLoad?.(), this.cancelPendingLoad = void 0, this.unbindDomEvents(), this.player &&= (this.player.destroy(), null), this.video && (this.video.src = "", this.video.removeAttribute("src")), this.video = null, this.listeners.clear();
|
|
348
|
+
}
|
|
349
|
+
seek(e) {
|
|
350
|
+
this.video && (this.video.currentTime = e);
|
|
351
|
+
}
|
|
352
|
+
setVolume(e) {
|
|
353
|
+
this.video && (this.video.volume = e);
|
|
354
|
+
}
|
|
355
|
+
setMuted(e) {
|
|
356
|
+
this.video && (this.video.muted = e);
|
|
357
|
+
}
|
|
358
|
+
setPlaybackRate(e) {
|
|
359
|
+
this.video && (this.video.playbackRate = e);
|
|
360
|
+
}
|
|
361
|
+
setQuality(e) {
|
|
362
|
+
this.player && (e === "auto" ? (this.player.updateSettings({ streaming: { abr: { autoSwitchBitrate: { video: !0 } } } }), this.emit("qualitychange", { level: "auto" })) : (this.player.updateSettings({ streaming: { abr: { autoSwitchBitrate: { video: !1 } } } }), this.player.setRepresentationForTypeByIndex("video", Number(e)), this.emit("qualitychange", { level: e })));
|
|
363
|
+
}
|
|
364
|
+
setSubtitle(e) {
|
|
365
|
+
if (this.player) {
|
|
366
|
+
if (e === null) this.player.setTextTrack(-1), this.enforceSingleNativeTextTrack(null);
|
|
367
|
+
else {
|
|
368
|
+
let t = this.player.getTracksFor("text").findIndex((t, n) => this.matchesTrackId(t, n, e));
|
|
369
|
+
t >= 0 && (typeof this.player.enableText == "function" && this.player.enableText(!0), this.player.setTextTrack(t), this.enforceSingleNativeTextTrack(t));
|
|
370
|
+
}
|
|
371
|
+
this.syncTracks();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
setAudioTrack(e) {
|
|
375
|
+
if (this.player) {
|
|
376
|
+
let t = this.player.getTracksFor("audio"), n = t.findIndex((t, n) => this.matchesTrackId(t, n, e));
|
|
377
|
+
if (n >= 0) {
|
|
378
|
+
let e = t[n];
|
|
379
|
+
typeof this.player.setInitialMediaSettingsFor == "function" && this.player.setInitialMediaSettingsFor("audio", {
|
|
380
|
+
lang: e?.lang,
|
|
381
|
+
index: e?.index,
|
|
382
|
+
role: Array.isArray(e?.roles) ? e.roles[0] : void 0
|
|
383
|
+
}), this.player.setCurrentTrack(e);
|
|
384
|
+
}
|
|
385
|
+
this.syncTracks();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
on(e, t) {
|
|
389
|
+
let n = e;
|
|
390
|
+
return this.listeners.has(n) || this.listeners.set(n, []), this.listeners.get(n).push(t), () => this.off(e, t);
|
|
391
|
+
}
|
|
392
|
+
off(e, t) {
|
|
393
|
+
let n = e, r = this.listeners.get(n);
|
|
394
|
+
if (!r) return;
|
|
395
|
+
let i = r.indexOf(t);
|
|
396
|
+
i > -1 && r.splice(i, 1);
|
|
397
|
+
}
|
|
398
|
+
emit(e, t) {
|
|
399
|
+
let n = e, r = this.listeners.get(n);
|
|
400
|
+
if (r) for (let e of [...r]) e(t);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
//#endregion
|
|
404
|
+
export { e as DashEngine };
|