-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview-box.js
73 lines (63 loc) · 1.83 KB
/
preview-box.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { css, html, LitElement } from 'lit';
import pillarbox from '@srgssr/pillarbox-web';
/**
* `PreviewBox` is a LitElement component that creates a pillarbox player
* with specific styling and functionalities, including the ability to apply
* custom CSS.
*
* @element preview-box
*
* @property {String} appliedCss CSS styles that can be applied to the video player.
* @property {String} [src='urn:rts:video:14318206'] The media to be loaded by the player,
* @property {String} [type='srgssr/urn'] The type of media to be loaded.
*
* @example
* <preview-box></preview-box>
*/
class PreviewBox extends LitElement {
static properties = {
appliedCss: { type: String },
mediaSrc: { type: String },
type: { type: String }
};
static styles = css`
.player-container {
width: 100%;
height: 100%;
}
`;
constructor() {
super();
this.mediaSrc = 'urn:rts:video:14318206';
this.type = 'srgssr/urn';
}
render() {
// TODO Remove the player container once this is resolved: https://github.com/videojs/video.js/pull/8679
return html`
<style>${this.appliedCss}</style>
<div class="player-container">
<video id="preview-player"
class="pillarbox-js"
controls crossOrigin="anonymous">
</video>
</div>
`;
}
updated(_changedProperties) {
super.firstUpdated(_changedProperties);
if (['mediaSrc', 'type'].some(property => _changedProperties.has(property))) {
this.player?.dispose();
const el = this.shadowRoot.getElementById('preview-player');
this.player = pillarbox(el, {
muted: true,
restoreEl: true
});
this.player.src({
src: this.mediaSrc,
type: this.type,
disableTrackers: true
});
}
}
}
customElements.define('preview-box', PreviewBox);