youtube-api - 时间更新事件 [英] youtube-api - Event on timeupdate

查看:40
本文介绍了youtube-api - 时间更新事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 IFrame 嵌入的 YouTube 到达特定帧时,是否可以引发事件?

Is it possible to raise an event when IFrame embedded YouTube reach a specific frame?

我正在寻找类似于 HTML5 播放器 timeupdate 事件的东西.

I am looking for something similar to HTML5 player timeupdate event.

我不是在寻找使用 setInterval 来检查当前位置(如 指定时间的 Youtube API 事件),我想知道是否有原生 API 支持此类功能.

I am not looking for using a setInterval to check the current position (as suggested in Youtube API event on a specified time), I would like to know if there is a native API to support such feature.

推荐答案

这是不可能的,因为没有这样的 事件.尽管不能直接尝试,但您可以尝试这样的操作,例如,如果您需要视频来结束特定点,您可以使用加载参数来执行此操作,就像这样.

This is not possible as there is no such event within the iFrame API. Although it is not directly possible you could try something like this, if you need a video to end a specific point for example you can use load parameters to do this, like so.

loadVideoById({'videoId': 'bHQqvYy5KYo',
           'startSeconds': 5,
           'endSeconds': 60,
           'suggestedQuality': 'large'});

之后,您将连接到 onStateChange 事件并取决于您想继续玩什么,询问有关时间范围等的问题.

After that you would hook into the onStateChange event and depends on what you want to do continue playing, ask a question about up to the timeframe etc.

但是,如果这是为了在移动设备上使用而设计的,您必须按照大多数移动浏览器进行考虑(参考资料说 iOS,我认为 android 也是如此).

However if this is designed to be used on mobile you must consider as per most mobile browsers (references says iOS, i think android does too).

警告:为了防止用户自行承担费用通过蜂窝网络进行未经请求的下载,无法在 iOS 上的 Safari 中自动播放嵌入式媒体 - 用户始终启动播放."

"Warning: To prevent unsolicited downloads over cellular networks at the user’s expense, embedded media cannot be played automatically in Safari on iOS — the user always initiates playback."

因此,如果视频结束或暂停,您无法切实地重新启动/恢复视频,用户必须始终这样做.

So if a video ends or pauses you can not pragmatically restart/resume the video, the user must always do it.

这篇关于youtube-api - 时间更新事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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