Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoplay Policy Changes on Chrome #395

Closed
edencorbin opened this issue May 4, 2018 · 17 comments
Closed

Autoplay Policy Changes on Chrome #395

edencorbin opened this issue May 4, 2018 · 17 comments

Comments

@edencorbin
Copy link

https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

I ran into an issue (with latest 1.5+ version of react-player) where videos stopped playing on start, reading this article a video must be muted to autoplay. With the following settings the video would still not auto play in react-player (I got it working fine in vanilla video tag):

<ReactPlayer
ref={el => this._videoRef = el}
volume={0}
muted={true}
url={this.props.url}
width={this.props.width}
height={this.props.height}
loop={false} />

Is this a known issue, or do I have a setting wrong?

@alexgarces
Copy link

alexgarces commented May 8, 2018

@edencorbin It also happened to me, but I figured it out a way to make the autoplay work (at least by now). It's kind of hacky but it is working for me for all platforms (Vimeo, YouTube, mp4) and popular browsers (Chrome, FireFox, Safari).

  1. Render the component with these props:

<ReactPlayer volume={0} onReady={this.handleOnReady} playing={this.state.playing} url={this.props.url} />

  1. Set playing in your component state as false: state = { playing: false }.

  2. Add a handleOnReady method as a callback via onReady prop to change the state. I recommend to add a small timeout (necessary for Vimeo).

handleOnReady = () => setTimeout(() => this.setState({ playing: true }), 100);

Hope it works for you!

@ethanshar
Copy link

Unfortunately @alexgarces your solution did not work for me.

I did come across this,
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
and it appears this issue has started after Youtube policy regarding autoplay has changed.

I didn't notice recently a change in the behavior of video autoplay, but now I understand clearly what's causing it.

Interacting with the page (simple click will do) prior to video load will fix the autoplay, unfortunately this is something we can't program (fake clicks don't work).

In the article they suggest other options, but I would hope to have one included in this library.

@edencorbin
Copy link
Author

@ethanshar I found that article too, and we ended up going to a plain video tag as our application cannot require user interaction prior to playing the video. It's working for use, we start the video muted. I like allot about react-player, but until this is resolved/supported we are using vanilla video tag.

@cookpete
Copy link
Owner

@edencorbin ReactPlayer uses a <video> tag under the hood when playing file URLs. You may need to add autoPlay and muted attributes manually via the config prop:

<ReactPlayer
  url='file.mp4'
  playing
  muted
  config={{ file: { attributes: {
    autoPlay: true,
    muted: true
  }}}}
/>

Ideally we should apply autoPlay and muted automatically if the playing and muted props are set.

As for YouTube and other players, this will be an ongoing battle with each API to retain the previous behaviour. I can't see a player param or other way to initialise a muted YouTube player to enable autoplay on the latest Chrome.

@cookpete
Copy link
Owner

I can't see a player param or other way to initialise a muted YouTube player to enable autoplay on the latest Chrome.

So it turns out you can pass in mute: 1 as a player param, this just isn't documented anywhere. Similarly, I guess this should be set when the muted prop is set.

@pugson
Copy link
Contributor

pugson commented May 14, 2018

@cookpete Changing mute: 1 to mute: 0 doesn't seem to be affecting the player after it has already rendered and started playing. Is that what you experience as well or am I doing something wrong?

@cookpete
Copy link
Owner

@pugson This is something that will be fixed soon for the YT player. All muting/autoplay behaviour needs to be sorted for every player. I'm also battling with karma tests no longer working on Travis (presumably because of a similar issue).

@cookpete
Copy link
Owner

This should be fixed in 1.5.1, but note the new readme section about autoplay. ReactPlayer must be muted to autoplay on Chrome 66 and later.

@hmontes
Copy link

hmontes commented Jun 5, 2018

Why i can play youtube videos normally but vimeo videos don't start?

(Autoplay works fine in youtube but don't in vimeo). Chrome disabled autoplay except for muted video but the video works normally in youtube

@jacobduursma
Copy link

You're not alone, we have the same issue @hmontes, sometimes it looks like vimeo will auto play but nothing actually is loading and then you have to press pause & play to actually play the media.

@cookpete
Copy link
Owner

cookpete commented Jun 5, 2018

@hmontes @jacobduursma I am assuming you are setting muted={true} when trying to autoplay videos? If Vimeo videos aren't auto-playing when muted then something is wrong, but I can't reproduce this.

Also worth checking out chrome://media-engagement/ and see how high youtube and vimeo appear in the list. It's possible that you have played enough YouTube videos enough for your MEI to be high enough to allow autoplay of non-muted videos, but not for Vimeo.

@jacobduursma
Copy link

You're right @cookpete, it does work when muted={true}, however in our case we want the media to play with sound (it's primarily for music), however the player loads after an interaction with the app, i.e. the clicking of an item from a list. Youtube and other providers work fine, just not vimeo.

It was my understanding that if interaction had taken place on the domain such as a click that it would be fine? For example even if I change chrome://flags/#autoplay-policy to document user activation required it still works fine for youtube, but not vimeo.

david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue Dec 23, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue May 23, 2020
albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
@Ranamalsingh12
Copy link

@cookpete Thanks for this solution
config={{ file: { attributes: {
autoPlay: true,
muted: true
}}}}
it worked for me.

@sandesh9680
Copy link

config={{ file: { attributes: {
autoPlay: true,
muted: true
}}}}
it worked for me also thankyou

webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
@killerburn69
Copy link

config={{ file: { attributes: {
autoPlay: true,
muted: true
}}}}
can i add with work for ytb in TS

@Ranamalsingh12
Copy link

Yes you can

@VadimChorrny
Copy link

@ethanshar I found that article too, and we ended up going to a plain video tag as our application cannot require user interaction prior to playing the video. It's working for use, we start the video muted. I like allot about react-player, but until this is resolved/supported we are using vanilla video tag.

Hey! I have the same issue.
How did you solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests