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

查看:264
本文介绍了使用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?

推荐答案

我修改了$ C $从 YouTube的玩家C iframe的API参考嵌入以若干秒后暂停播放。

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

演示

Demo

在code的工作方式是等待 onPlayerStateChange 事件。当事件触发时,它会检查该事件,看它是否是一个玩转事件。如果是,它计算从当前时间( getCurrentTime()法)到所需的停顿点的剩余时间(硬codeD作为 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天全站免登陆