15
votes

There is an Autoplay feature on YouTube which plays the next recommended video.

How do I go about enabling this in an embedded YouTube player?

The YouTube API here explains an autoplay function but this isn't the same. The feature they describe is automatically playing the video as soon as the web page is loaded.

Is there any way to implement the Autoplay feature found on YouTube in an embedded video frame?

3
the question might be a duplicate. this might help: stackoverflow.com/questions/19725950/…ungalcrys

3 Answers

3
votes

as i understand the idea is to have the same behaviour using embedded youtube (YouTube Iframe-API) as using the normal youtube.com with autoplay set to true.

the only way i found so far is to fetch a videoId through an api call as described here: https://stackoverflow.com/a/19732072/10956686 and then use player.loadVideoById() after PlayerState.ENDED event is fired.

    function onPlayerStateChange(event) {     
        if (event.data == YT.PlayerState.ENDED && !done) {        
            player.loadVideoById(myFetchedNextVideoId);
        }       
    }

but this could lead to a lot of API quota usage.

0
votes

As per the options listed in the youtube api reference page https://developers.google.com/youtube/iframe_api_reference

there aren't any specific option to enable that feature you are looking for.


But, You can achieve this through other approach to make the embedded youtube video player to play the next video automatically.

for that, you have to embed a video from playlist instead of embedding a video directly

<iframe width="727" height="409" src="https://www.youtube.com/embed/NTM4kxNjAIY?list=PLelK7aEMtfK2wpv7tv472alrDpNwO_0jw" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
0
votes
<iframe width="727" height="409" src="https://www.youtube.com/embed/211t6r12XPQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe> 

Maybe this is AI or UI copy link to some website