问题
I am trying to get an embedded YouTube video to autoplay. I have set the ?autoplay=1 in the parameter but this seems to be deprecated. I have not been able to find any documentation on it though.
How can I get autoplay to work on videos?
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
回答1:
If you don't mind that the video autoplays muted, you can add the following parameter in the YouTube URL:
&rel=0&mute=1
Here is the iframe with autoplay enabled and muted1
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1&rel=0&mute=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
- Test made in Google Chrome Version 72.0.3626.119 (Build oficial) (32 bits)
1 I really don't know why the "mute" option must be set in the URL (and only in Google Chrome), because in Firefox and Edge the video autoplays without adding the mute
parameter.
来源:https://stackoverflow.com/questions/54889615/youtube-autoplay-issue