Certain functions in YouTube AS3 API return wrong values
I'm now working on a certain AS3 application. The code is pretty much the AS3 example from the documentation:
// The player SWF file on www.youtube.com needs to communicate with your host
// SWF file. Your code must call Security.allowDomain() to allow this
// communication.
Security.allowDomain("www.youtube.com");
// This wi开发者_如何学JAVAll hold the API player instance once it is initialized.;
var player:Object;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
function onLoaderInit(event:Event):void
{
stage.addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(event:Event):void
{
// Event.data contains the event parameter, which is the Player API ID
trace("player ready:", Object(event).data);
// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
player = loader.content;
player.loadVideoById("nJ3MSCLBpaM");
// Set appropriate player dimensions for your application;
setPlayerSize();
stage.addEventListener(Event.RESIZE, updatePlayerSize);
}
function setPlayerSize():void
{
player.y = 0;
player.x = 0;
player.setSize(stage.stageWidth, stage.stageHeight);
}
function getVideoBytesTotal()
{
return player.getVideoBytesTotal();
}
function getVideoBytesLoaded()
{
return player.getVideoBytesLoaded();
}
function getVideoStartBytes()
{
return player.getVideoStartBytes();
}
for some reason, when I call one of the last three functions after the video has loaded (and while it is playing) all I get is 0, from all of them. Why is that?
Those functions are deprecated. Use
player.getVideoLoadedFraction()
instead.
精彩评论