react-player icon indicating copy to clipboard operation
react-player copied to clipboard

React player is not loading the video initially

Open ShahriarDhruvo opened this issue 4 years ago • 15 comments

Current Behavior

Basically I am trying to load the video from my public folder (also tried a s3 link):

<div>
      <ReactPlayer controls url={video_url} />
      <video width="320" height="240" controls>
          <source src={video_url} type="video/mp4" />
          Your browser does not support the video tag.
      </video>
  </div>

But the react player is not loading the video initially: see the photo

As you can see from the code and the screenshot I am using both ReactPlayer and vanilla "video" tag to show you that it is not a path issue. However if I change the path manually from the code --> "/tmp/video/lol.mp4" to "tmp/video/lol.mp4" (or anything as long as it is a valid path, I can use both "/tmp/video/lol.mp4" and "tmp/video/lol.mp4" as they both points to the same local video in the public folder) it causes react to update the dom and then both of them show the video just fine. But if refresh/hard-refresh the page the issue persist and it again goes away if react update the dom for some code change. But this is not the case for youtube video links they works just fine either way.

I can also reproduce this in codesandbox!! CodeSandbox link is in below. Is there something wrong with my computer??

Steps to Reproduce

My main project is on nextjs however I have created both brand new nextjs and react project by "yarn create next-app --typescript" and "yarn create react-app my-app --template typescript" respectively. But this problem persist eitherway :(

My pacage versions:

"next": "12.2.5", "react": "^18.2.0", "react-dom": "^18.2.0", "react-player": "^2.11.0", "react-scripts": "5.0.1", "typescript": "^4.4.2",

Environment

  • I have tried with local url "/tmp/video/lol.mp4" and a url from s3 --> "https://test1213123-bucket.s3.ap-southeast-1.amazonaws.com/720p.mp4"
  • Browser: Chrome Version 106.0.5249.119 (Official Build) (arm64)
  • Operating system: MacOS Monterey 12.6
  • CodeSandBox Implementation: https://codesandbox.io/s/patient-https-c4t9r2?file=/src/App.js

ShahriarDhruvo avatar Oct 12 '22 19:10 ShahriarDhruvo

I have experienced this same issue. I believe this issue is caused by React StrictMode, you can disable this and the videos should play without any issue.

tomheaton avatar Oct 12 '22 20:10 tomheaton

Is this because react 18's next dom + next dom or whatever weird issue? Anyway turning off strict mode is not the way. It's like the frontend can't read weather the app is currently authenticated so the solution is to remove httponly from auth_token!! What I am saying is there has to be better solution as far as I remember it worked just fine before I updated this package along with react 😭

ShahriarDhruvo avatar Oct 12 '22 20:10 ShahriarDhruvo

True, the real issue needs to be fixed but it works and your prod will be okay until its fixed 😃

tomheaton avatar Oct 12 '22 20:10 tomheaton

Yes and thanks for the strict mode reference, I forgot to check by turning off that and it worked 😀

ShahriarDhruvo avatar Oct 12 '22 20:10 ShahriarDhruvo

Hopefully fixed by https://github.com/cookpete/react-player/pull/1538

cookpete avatar Feb 03 '23 21:02 cookpete

@cookpete, i think the issue still persist in next13 with strict-mode enabled

knowsarzehmeh avatar Feb 05 '23 10:02 knowsarzehmeh

@knowsarzehmeh I haven’t published a new version yet. Will do soon.

cookpete avatar Feb 05 '23 19:02 cookpete

I confirm that updating from 2.11.0 to 2.12.0 seems fixing this issue. Thanks

[EDIT] @cookpete

const url = 'https://p.scdn.co/mp3-preview/0ed0e3241d7dd381271156710b7153308ddfbb89';

<ReactPlayer url={url} ... /> // works
// but
ReactPlayer.canPlay(url); // false

vincentwinkel avatar Apr 04 '23 11:04 vincentwinkel

The issue still persists for a youtube link. It plays after clicking on a navlink, but doesn't on the very first load or when reloading. Using:

"react": "18.2.0",
"react-player": "2.13.0",

Also:

  • disabled StrictMode, same thing
  • using tsx and a functional component, not sure if that changes anything
  • correctly linked ref

Please let me know if you want me to create a minimal example?

Similar questions: https://stackoverflow.com/questions/61271284/audio-dont-play-again-on-page-refresh-react https://stackoverflow.com/questions/76425979/reactplayer-doesnt-load-videos-initially https://stackoverflow.com/questions/69425243/react-player-how-to-handle-play-pause-state-with-autoplay

stephanebruckert avatar Sep 06 '23 19:09 stephanebruckert

I had this issue today and I solved it by converting my .mov video to .mp4 format. It seems some browsers don't like .mov video files.

Learn more: Web video codec guide

flacial avatar Dec 07 '23 23:12 flacial

I'm having the same problem while trying to stream .m3u8 file. Sometimes it works, sometimes only show a white control bar, with no video (The only diference between both cases, is that when it works, I can see data image svg requests).

Looks very random to me, never know if the stream will load after refreshing the page. The stream URL is always the same for both cases.

Really need help with this issue. Already tried removing strict mode, both downgrande and upgrade hls version, and still have this unpredictable bug.

EDIT: Debugging streams can be tricky as sometimes runs smoothly on VLC player, and not in react-player only but browsers in general seem to have a strange behavior. Read my answer to @Spanishiwa below for more information.

danielfs13 avatar Dec 22 '23 18:12 danielfs13

I'm also trying to stream .m3u8 files and I'm experiencing something very similar to danielfs13. With the same stream URL (absolute path player.vimeo m3u8 link), the video will sometimes load in Safari, but sometimes won't load in Chrome. Then, with no code changes the player will load correctly in both browsers, seemingly randomly.

The ReactPlayer key in React Component Dev Tools is always "File" (sounds right). I updated to the latest react-player version, but removing strict mode is not an option for me.

Spanishiwa avatar Feb 02 '24 19:02 Spanishiwa

I'm also trying to stream .m3u8 files and I'm experiencing something very similar to danielfs13. With the same stream URL (absolute path player.vimeo m3u8 link), the video will sometimes load in Safari, but sometimes won't load in Chrome. Then, with no code changes the player will load correctly in both browsers, seemingly randomly.

The ReactPlayer key in React Component Dev Tools is always "File" (sounds right). I updated to the latest react-player version, but removing strict mode is not an option for me.

I can confirm this is not related to react-player only.

After more testing, I realized that the streams had problems on other players. I also tested directly in Chrome with an extension to run m3u8 streams, and the problem persisted. It turns out that the problem was in the ngnix server settings for video conversion through FFPMEG. After my team fixed these problems, streams run much better.

However, there was no success for channels generated by Amazon IVS, the same random behavior persisted with black screens after many attempts. It would be interesting if someone has a solution for this.

I apologize and will edit my other post, I was confused because the streams somehow run fine in VLC, but apparently it is more related to a problem with browsers in general, and not just react-player.

danielfs13 avatar Feb 19 '24 13:02 danielfs13

I am also facing this issue, I tried Mozilla Firefox it works. But in Chrome, it does not. Can anybody help me with this issue?

AnandJGITHUB avatar Apr 08 '24 06:04 AnandJGITHUB

I am also facing this issue, I tried Mozilla Firefox it works. But in Chrome, it does not. Can anybody help me with this issue?

You must set muted={true} https://github.com/cookpete/react-player?tab=readme-ov-file#autoplay

lerryklitzke avatar May 29 '24 14:05 lerryklitzke