cookpete / react-player

A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
https://cookpete.github.io/react-player
MIT License
8.98k stars 1.12k forks source link

Offline mode and hls.js #1582

Closed sharon2469 closed 1 year ago

sharon2469 commented 1 year ago

I have an environment that creates a playlist (m3u8), everything works smoothly until the moment I disconnect from the Internet. My system continues to generate a playlist and I continue to listen to it with the help of the ReactPlayer library, the problem starts with the fact that the library uses hls.js and it tries to take data from: https://cdn.jsdelivr.net/npm/hls.js@1.1.4/dist/ hls.min.js

I did GOOGLE about it and thought that if I download the HLS.JS to my project and load it it will solve the problem, but I can't figure out how I can transfer the HLS.JS I downloaded to the ReactPlayer library. I checked the API of the library and it mentions hlsOptions but without much explanation as to how I can transfer an instance of the current location of the HLS.JS (I need my system to work OFFLINE as well !!!( can someone please suggest how can I solve it?

cookpete commented 1 year ago

I can't figure out how I can transfer the HLS.JS I downloaded to the ReactPlayer library.

You don’t need to include hls.js in the ReactPlayer library. You should be able to just save https://cdn.jsdelivr.net/npm/hls.js@1.1.4/dist/hls.min.js and use it in your project (either via a <script> tag or however you import local vendor scripts).

If you’ve loaded it into your page when ReactPlayer renders, the window.Hls global will be available, and ReactPlayer won’t need to go and fetch hls.js.

mislavmiocevic commented 1 month ago

@cookpete if we still want to add hls.js locally, is this how you would do it?:

import Hls from 'hls.js';

...

if (typeof window !== 'undefined' && !window.Hls) {
   window.Hls = Hls;
}

return (...);

I am using Next.js

P.S. This is working btw, but I wanted to ask is there something better within the player's configuration