Autoplay video when opening the video page
Add autoPlay/playsInline to the local video element, autoplay: 1 to the YouTube IFrame API playerVars, and ?autoplay=1 to the plain-iframe fallback. Best-effort: browsers may block unmuted autoplay, so the play button stays as fallback.
This commit is contained in:
parent
a89f972afa
commit
b1faeb3729
2 changed files with 64 additions and 2 deletions
|
|
@ -178,7 +178,7 @@ function Player({ video }: Props) {
|
|||
const player = new window.YT.Player(host, {
|
||||
videoId: video.youtube_video_id,
|
||||
host: 'https://www.youtube-nocookie.com',
|
||||
playerVars: { playsinline: 1 },
|
||||
playerVars: { playsinline: 1, autoplay: 1 },
|
||||
events: {
|
||||
onReady: () => {
|
||||
if (cancelled || timedOut) return
|
||||
|
|
@ -251,6 +251,8 @@ function Player({ video }: Props) {
|
|||
<video
|
||||
ref={videoRef}
|
||||
controls
|
||||
autoPlay
|
||||
playsInline
|
||||
src={video.local.media_url!}
|
||||
onError={() => {
|
||||
setLocalFailed(true)
|
||||
|
|
@ -276,7 +278,7 @@ function Player({ video }: Props) {
|
|||
<div className="player-wrapper">
|
||||
{ytApiStatus === 'timeout' ? (
|
||||
<iframe
|
||||
src={`https://www.youtube-nocookie.com/embed/${video.youtube_video_id}`}
|
||||
src={`https://www.youtube-nocookie.com/embed/${video.youtube_video_id}?autoplay=1`}
|
||||
title={video.title}
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowFullScreen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue