vidstack / player

UI components and hooks for building video/audio players on the web. Robust, customizable, and accessible. Modern alternative to JW Player and Video.js.
https://vidstack.io
MIT License
1.9k stars 114 forks source link

Types broken with `MediaProviderAdapter ` #1239

Closed Mister-Hope closed 2 months ago

Mister-Hope commented 2 months ago

See https://www.vidstack.io/docs/wc/player/api/providers/hls?styling=default-theme#loading

image

The docs says that we can set library property on provider to change how to load the provider (Background: JSDeliver is nearly inaccessible in China)

However, the provider has type MediaProviderAdapter | null, and there is no library field on MediaProviderAdapter:

image

mihar-22 commented 2 months ago

That soft provider type checking was designed for CDN users so TS types are not considered there. You have some options:

Option 1. Use player.provider which will cast to the correct type:

if (player.provider?.type === 'hls') {
}

Option 2. Cast to AnyMediaProvider:

import type { AnyMediaProvider } from 'vidstack';

const provider = event.detail as AnyMediaProvider;
if (provider?.type === 'hls') {
}

Option 3. Cast the type yourself:

import type { HLSProvider } from 'vidstack';

if (provider?.type === 'hls') {
  const hls = provider as HLSProvider;
}
Mister-Hope commented 2 months ago

Hi, you may need to reopen this:

image

The type is different with docs:

image image

From the docs, VidStack is expecting dash package default import while the types is expecting MediaPlayer on it.

Please fix one of this.

Mister-Hope commented 2 months ago

@mihar-22 reping