0
votes

I am using swfobject.js version 2.2.

I am calling swfobject.embedSWF with the last parameter (callbackFn) set to a local function in my Javascript code.

After that, two different routines are invoked: 1. My callback function 2. 'onYouTubePlayerReady', which is a callback function defined by the swfobject API.

What is the difference between these two, and on which one should I rely in order to be sure that the video has uploaded and is ready to play?

I am asking this, because on Safari, only my callback function is invoked, and so I need to know whether it is safe to rely on it.

1

1 Answers

0
votes

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.