react-player
react-player copied to clipboard
Autoplay won't start on 2.11.0
Current Behavior
The video won't start at all
Expected Behavior
The video should start
Steps to Reproduce
- React player 2.11.0
- playing = true
- loop = true
- muted = true
Environment
- Browser: Brave, Chrome, Safari
- Operating system: Mac OS
If you are using React 18 refer this https://github.com/cookpete/react-player/issues/1508#issuecomment-1264387346
What if I'm not on React 18?
This worked for me. Could probably remove the volume and muted prop
<ReactPlayer
url={source.url}
className="react-player"
width={width}
height={height}
loop={true}
playing={inView}
playsinline={true}
volume={0.5}
muted={true}
onReady={(e) => {
const player = e.getInternalPlayer();
player.setAttribute('muted', 'true');
}}
/>
Documentation for autoplay
could be better.
We know what HTML5 needs for this to work, but what does ReactPlayer need?
Considering it doesn't pass props onto the video node its not really browser standards friendly.
What type of URL are you trying to play? That’s kind of important. Every third party player that ReactPlayer loads will have its own autoplay nuances, and always be at the mercy of browser autoplay nuances. It’s a losing battle to be honest.
On Android Phone - Chrome, it will works by just setting props muted={true}
,
On IOS Safari - you will have to set the playsinline={true}
also to force the sound of the video to be muted. If you are using youtube player, by just setting muted to true is just enough