YouTube IFrame API: Is conditional autoplay queue progression required when document.visibilityState is 'hidden'?

8 hours ago 1
ARTICLE AD BOX

I'm building a video archive site that uses the YouTube IFrame Player API to embed VODs from official channels. The site has a user-toggleable "autoplay next video" feature similar to YouTube's own autoplay setting.

I'm trying to understand the correct interpretation of YouTube's Developer Policy on background playback for a specific scenario.

Scenario

1. User explicitly clicks "Play" on Video A. 2. Video A starts playing in a visible IFrame player. 3. User minimizes the browser window or switches to another tab. (document.visibilityState becomes 'hidden') 4. Video A ends. 5. The autoplay feature attempts to load and play Video B.

What the policy says

The Developer Policies prohibit:

Allow for background play of the YouTube video player. Example: Using YouTube's API to allow videos to play even when your API service window is closed or minimized.

My interpretation

I believe this prohibition targets developer-implemented mechanisms that explicitly enable background playback (hidden iframes, audio extraction, wake locks, service workers bypassing browser autoplay restrictions).

In my scenario, I'm not implementing any such bypass. The browser's default autoplay handling determines whether Video B starts playing or not.

Two implementation options

Option A: No explicit gating

function onPlayerStateChange(event) { if (event.data === YT.PlayerState.ENDED) { const nextId = playlist.shift(); if (nextId) player.loadVideoById(nextId); } }

Option B: Explicit visibility gating

let pendingNext = null; function onPlayerStateChange(event) { if (event.data === YT.PlayerState.ENDED) { if (document.visibilityState !== 'visible') { pendingNext = playlist.shift(); return; } const nextId = playlist.shift(); if (nextId) player.loadVideoById(nextId); } } document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible' && pendingNext) { player.loadVideoById(pendingNext); pendingNext = null; } });

My question

Does Option A constitute "allowing for background playback" in the sense prohibited by the YouTube Developer Policies, even though the developer is not implementing any explicit bypass mechanism?

In other words: is Option B (explicit gating) required for policy compliance, or is Option A acceptable as long as no audio extraction, hidden players, or autoplay bypass mechanisms are used?

What I've already reviewed

YouTube API Services - Developer Policies Required Minimum Functionality Complying with YouTube's Developer Policies

I couldn't find an explicit clarification for this specific case (user-initiated foreground playback that continues into background, followed by autoplay queue progression).

Read Entire Article