使用 YoutubeAPI 播放 YouTube 视频直到特定时间并暂停 [英] Use YoutubeAPI to play youtube video until a particular time and pause

查看:78
本文介绍了使用 YoutubeAPI 播放 YouTube 视频直到特定时间并暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 Youtube API 播放视频直到视频中的某个点然后暂停?

Is there a way to use the Youtube API to play a video until a certain point in the video and then pause it?

推荐答案

我修改了 用于 iframe 嵌入的 YouTube 播放器 API 参考,用于在特定秒数后暂停播放.

I've modified the code from the YouTube Player API Reference for iframe Embeds to pause play after a certain number of seconds.

演示

代码通过等待 onPlayerStateChange 事件来工作.当事件触发时,它会检查该事件是否为 PLAYING 事件.如果是,它会计算从当前时间(getCurrentTime() 方法)到所需暂停点(硬编码为 stopPlayAt 变量)的剩余时间.它设置一个 Javascript 计时器来等待该差异,然后向 API 传递一个命令以暂停视频.

The code works by waiting for the onPlayerStateChange event. When the event fires, it checks the event to see if it's a PLAYING event. If it is, it calculates the remaining time from the current time (getCurrentTime() method) to the desired pause point (hardcoded as the stopPlayAt variable). It sets a Javascript timer to wait that difference and then pass the API a command to pause the video.

这篇关于使用 YoutubeAPI 播放 YouTube 视频直到特定时间并暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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