Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 820
Fauntleroy Avatar asked Nov 06 '15 16:11

Fauntleroy


People also ask

What is YouTube IFrame api?

The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played.


1 Answers

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.

like image 176
David Sanders Avatar answered Nov 15 '22 10:11

David Sanders