Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoplay next video in embedded YouTube player

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?

like image 815
Jack Paul Avatar asked Mar 17 '16 05:03

Jack Paul


1 Answers

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.

like image 168
tagtraum Avatar answered Sep 21 '22 23:09

tagtraum