YouTube iframe player won't play when tab/window doesn't have focus
Asked Answered
C

2

6

When I attempt to create a YouTube iframe player with autoplay in a Google Chrome tab that doesn't have focus the video won't start until the tab gains focus. Even manually calling playVideo won't get the video to play. At first I thought this was part of the new feature that prevents YouTube videos from playing in newly opened tabs, but this only seems to effect Google Chrome.

You can replicate the issue in the wild by doing the following:

  • Go to http://www.tandem.io and create a room
  • Go to your newly created room in Chrome AND firefox (or Opera)
  • Mute the player in Opera
  • Make sure the Chrome tab does not have focus
  • Add a YouTube video to the playlist in Opera
  • The video won't play in Chrome until the tab/window is active
Clave answered 6/11, 2015 at 16:5 Comment(3)
Isn't that a feature? I assume your question is "how to make it play?" Because you don't ask anything.Keratitis
I suppose the question is, why is autoplayed video behavior inconsistent in Chrome even when the tab has had focus once?Clave
@BasvanStein I would like to ask the question how to make it play. :)Approbate
J
1

I believe this is a Chrome browser feature in that it prevents JS from firing if the tab is blurred.

You can recreate this by visiting youtube.com and opening a number of videos in new tabs but not visit those tabs, the blurred tabs will not begin autoplaying the video until it has been focused at least once.

Jaborandi answered 6/11, 2015 at 16:18 Comment(5)
After trawling through codereview.chromium.org/1292433002 I've found that, if a tab has had focus at some point, it should be able to autoplay videos. The only problem with this is that the behavior is extremely inconsistent in practice. I'm going to start building some extremely specific test cases to see why this functionality isn't working as advertised.Clave
@Clave Any luck figuring out how to disable / work around this "feature"Approbate
@Approbate Nope. Just waiting patiently for Google to realize the error of their ways...Clave
@Clave To the firefox mobile! :)Approbate
Any workarounds on this yet? firefox seems to be doing the sameImprovisator
W
-2

You can Disable this in chrome://flags

In Chrome - chrome://flags/#disable-gesture-requirement-for-media-playback

Widthwise answered 23/11, 2016 at 16:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.