react-player: src is not set when using file
Current Behavior
When setting URL = a mp4 the video SRC is never set, thus the player never loads. Occasionally when hot reloading kicks in the player will work.
Expected Behavior
setting url="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4"
should work
also tried, url={[{src: 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4'}]}
Steps to Reproduce
- create react app
- import import ReactPlayer from ‘react-player/file’; OR import ReactPlayer from ‘react-player’;
- add player
<ReactPlayer url="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4" controls />
Other Information
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 18 (2 by maintainers)
Yep when i remove the strict mode, all works fine. Is there any solution for this issue?
I was facing also this issue (React 18.2.0 - react-player 2.11.0)
Comment (or removing)
<React.StrictMode>
tag is fixing that in development environment (NODE_ENV), it is working in production environment (when app is built) though since<React.StrictMode>
is ignored in productionI have same issue too. I think that ‘src’ should be set again when component is re-mounted.
https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state
Downgrading react-player to v2.10.1 or removing
<React.StrictMode>
fixes the issue. I believe the problem is PR #1360.The issue is yet to be resolved, I’m using 2.12.0
I can’t downgrade react because i use NextJS last version, but downgrading react-player to v2.10.1 is helped me. Thank you gues a lot.
I am also experiencing this issue:
I can also see an error returned by the onError call back with the following…
MEDIA_ELEMENT_ERROR: Empty src attribute
https://github.com/cookpete/react-player/pull/1612 fixes this
I have the same issue in React 18. Downgrading to v2.10.1 does NOT fix the issue. Everything is fine after removing
<React.StrictMode>
as mentioned previously in both v2.10.1 and v2.11.0. However, that is not an acceptable fix.In my function component, I do not render the video player at all if the URL string happens to be empty/null/undefined.
Here is part of the error that is generated from the
onError
callback. This same error happens in v2.10.1 and in v2.11.0 in React 18. You can see that my local video file path appears in thecurrentSrc
property so it looks like the component is receiving the proper URL.