gpt4 book ai didi

javascript - 如何检查 YT.Player 对象是否已准备好?

转载 作者:行者123 更新时间:2023-11-30 12:43:13 26 4
gpt4 key购买 nike

在同一页面的不同元素上创建了多个 YT.player 对象。

 player1 = new YT.Player( 'player-1' , {...
player2 = new YT.Player( 'player-2' , {...
player3 = new YT.Player( 'player-3' , {...

一些 div 可见性可以通过 Javascript 改变。在某些浏览器(例如 IE 11)上,只有在 DIV 可见时才会调用 Youtube Iframe API 的 onPlayerReady 回调。

  // 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}

是否有一些构建检查以查看 YT.player 对象是否已准备好?

换句话说,我可以在对播放器 1、播放器 2、播放器 3 调用 stopVideo 之前检查它们吗?因为如果我打电话

player-3.stopVideo()

并且 player-3 没有收到 onPlayerReady 事件,我得到一个“未知方法 stopVideo()”-Exception。

最佳答案

对于这个问题,我没有完美的解决方案。似乎有用的是检查这是否是一个函数

if ( typeof player-3.stopVideo === 'function' ) {
player-3.stopVideo()
}

最好的问候,

关于javascript - 如何检查 YT.Player 对象是否已准备好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23613442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com