forked from muxinc/media-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash-video-element.js
44 lines (31 loc) · 1.08 KB
/
dash-video-element.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { CustomVideoElement } from 'custom-media-element';
class DashVideoElement extends CustomVideoElement {
static shadowRootOptions = { ...CustomVideoElement.shadowRootOptions };
static getTemplateHTML = (attrs) => {
const { src, ...rest } = attrs; // eslint-disable-line no-unused-vars
return CustomVideoElement.getTemplateHTML(rest);
};
#apiInit;
attributeChangedCallback(attrName, oldValue, newValue) {
if (attrName !== 'src') {
super.attributeChangedCallback(attrName, oldValue, newValue);
}
if (attrName === 'src' && oldValue != newValue) {
this.load();
}
}
async load() {
if (!this.#apiInit) {
this.#apiInit = true;
const Dash = await import('dashjs-esm');
this.api = Dash.MediaPlayer().create();
this.api.initialize(this.nativeEl, this.src, this.autoplay);
} else {
this.api.attachSource(this.src);
}
}
}
if (globalThis.customElements && !globalThis.customElements.get('dash-video')) {
globalThis.customElements.define('dash-video', DashVideoElement);
}
export default DashVideoElement;