Skip to content

Commit

Permalink
feat(player): add new onLoad method to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Mar 21, 2024
1 parent a412d14 commit 2ce029f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vidstack/src/core/state/media-player-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class MediaPlayerDelegate {
remotePlaybackInfo,
playsInline,
savedState,
source,
} = this._media.$state;

if (canPlay()) return;
Expand Down Expand Up @@ -77,6 +78,8 @@ export class MediaPlayerDelegate {
{ storage, qualities } = this._media,
{ muted, volume, clipStartTime, playbackRate } = this._media.$props;

await storage?.onLoad?.(source());

const savedPlaybackTime = savedState()?.currentTime,
savedPlayingState = savedState()?.paused === false,
storageTime = await storage?.getTime(),
Expand Down
5 changes: 5 additions & 0 deletions packages/vidstack/src/core/state/media-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface MediaStorage {
getAudioGain(): Promise<number | null>;
setAudioGain?(gain: number | null): Promise<void>;

/**
* Called when media is ready for playback and new data can be loaded.
*/
onLoad?(src: Src): void | Promise<void>;

/**
* Called when the `mediaId` has changed. This method can return a function to be called
* before the next change.
Expand Down

0 comments on commit 2ce029f

Please sign in to comment.