Skip to content

Commit

Permalink
fix(player): load poster element in js player create
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Mar 26, 2024
1 parent aa46aae commit 2c56c58
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vidstack/src/global/layouts/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { VidstackPlayerLayoutLoader } from './loader';
export class VidstackPlayerLayout implements VidstackPlayerLayoutLoader {
constructor(readonly props?: Partial<DefaultLayoutProps>) {}

readonly name = 'vidstack';

async load() {
await import('../../elements/bundles/player-layouts/default');
await import('../../elements/bundles/player-ui');
Expand Down
1 change: 1 addition & 0 deletions packages/vidstack/src/global/layouts/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface VidstackPlayerLayoutLoader {
readonly name: string;
load(): void | Promise<void>;
create(): HTMLElement[] | Promise<HTMLElement[]>;
}
2 changes: 2 additions & 0 deletions packages/vidstack/src/global/layouts/plyr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { VidstackPlayerLayoutLoader } from './loader';
export class PlyrLayout implements VidstackPlayerLayoutLoader {
constructor(readonly props?: Partial<PlyrLayoutProps>) {}

readonly name = 'plyr';

async load() {
await import('../../elements/bundles/player-layouts/plyr');
}
Expand Down
12 changes: 12 additions & 0 deletions packages/vidstack/src/global/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '../elements/bundles/player';

import { defineCustomElement } from 'maverick.js/element';
import { isString, kebabToCamelCase } from 'maverick.js/std';

import type { MediaPlayerProps, TextTrackInit } from '../core';
Expand Down Expand Up @@ -33,6 +34,17 @@ export class VidstackPlayer {

player.setAttribute('keep-alive', '');

if (props.poster && layout?.name !== 'plyr') {
if (!customElements.get('media-poster')) {
const { MediaPosterElement } = await import('../elements/define/poster-element');
defineCustomElement(MediaPosterElement);
}

const poster = document.createElement('media-poster');
if (layout?.name === 'default') poster.classList.add('vds-poster');
provider.append(poster);
}

if (layout) {
if (!layout[LAYOUT_LOADED]) {
await layout.load();
Expand Down

0 comments on commit 2c56c58

Please sign in to comment.