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
2.29k stars 133 forks source link

Youtube & Vimeo provider throw provider destroyed error #1459

Open Benny739 opened 1 month ago

Benny739 commented 1 month ago

Current Behavior:

When youtube or vimeo provider are getting destroyed they are throwing a "provider destroyed" error. Problem is already mentioned in a discussion: #1378

Expected Behavior:

No error is thrown when provider gets destroyed

Steps To Reproduce:

  1. Switch to youtube or vimeo in the demo
  2. Switch to some other provider
  3. Error gets thrown
wplit commented 1 month ago

I get the same if trying to switch the src from Youtube to Vimeo or the other way around.

If I first set the src = '', and then to the Vimeo src after a timeout, there's no error.

reilnuud commented 4 weeks ago

I was able to avoid this error by exiting my onProviderChange function before processing the undefined provider:

const onProviderChange = provider => {
  // exit if no provider to prevent error
  if (!provider) {
    return;
  }
  if (isVimeoProvider(provider)) {
      // handle vimeo provider
  }
  if (isYouTubeProvider(provider)) {
    // handle youtube provider
  }
};

...

<MediaPlayer 
  onProviderChange={onProviderChange}
  {...}
>
  {...}
</MediaPlayer>