在嵌入式YouTube播放器中自动播放下一个视频 [英] Autoplay next video in embedded YouTube player

查看:56
本文介绍了在嵌入式YouTube播放器中自动播放下一个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YouTube上有一个自动播放功能,可播放下一个推荐的视频.

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

如何在嵌入式YouTube播放器中启用它?

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

此处的YouTube API 解释了自动播放功能,但这并不相同.他们描述的功能是在加载网页后自动播放视频.

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.

有什么方法可以在嵌入式视频帧中实现YouTube上的自动播放功能?

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

推荐答案

据我了解,该想法是使用嵌入式youtube(YouTube Iframe-API)的行为与使用正常youtube.com(自动播放设置为true)的行为相同.

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.

到目前为止,我发现的唯一方法是通过api调用来获取videoId,如下所述: https://stackoverflow.com/a/19732072/10956686 然后在PlayerState.ENDED事件触发后使用player.loadVideoById().

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);
        }       
    }

但这会导致大量的API配额使用.

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

这篇关于在嵌入式YouTube播放器中自动播放下一个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆