15

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?

1

3 Answers 3

3

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

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
<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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.