0

我正在使用 swfobject.js 2.2 版。

我正在调用 swfobject.embedSWF,并将最后一个参数 (callbackFn) 设置为我的 Javascript 代码中的本地函数。

之后,会调用两个不同的例程: 1. 我的回调函数 2. 'onYouTubePlayerReady',这是一个由 swfobject API 定义的回调函数。

这两者有什么区别,我应该依靠哪一个来确保视频已上传并可以播放?

我问这个,因为在 Safari 上,只有我的回调函数被调用,所以我需要知道依赖它是否安全。

4

1 回答 1

0

onYouTubePlayerReady is not a SWFObject method, it is an independent method supplied by YouTube's player API.

Your issue probably comes down to timing -- since onYouTubePlayerReady is part of the YouTube player API, it will not be available until the SWF has finished loading and ExternalInterface has been initialized by Flash Player.

SWFObject's callbackFn simply executes when the <object> has been successfully added to the page's markup, and does not indicate the SWF has loaded. In fact, SWFObject does not pay attention to whether the SWF loads at all.

However with a little bit of extra JavaScript you can poll the SWF to detect whether it has finished loading, then execute your custom script (in this case onYouTubePlayerReady).

This Stack Overflow thread discusses the polling, and here's a short tutorial explaining how to poll after embedding a SWF via SWFObject.

于 2012-09-04T05:42:51.037 回答