【问题标题】:Certain functions in YouTube AS3 API return wrong valuesYouTube AS3 API 中的某些函数返回错误值
【发布时间】:2011-09-18 20:29:03
【问题描述】:

我现在正在开发某个 AS3 应用程序。该代码几乎是文档中的 AS3 示例:

// 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 will 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();
}

由于某种原因,当我在视频加载后(并且在播放时)调用最后三个函数之一时,我得到的所有函数都是 0。这是为什么呢?

【问题讨论】:

  • 我注意到它只发生在 Firefox 中。 Chrome 运行良好。
  • 实际上我在 Chrome 上运行,但它不工作。 :O
  • 这个测试对你有用吗? code.google.com/apis/ajax/playground/…
  • 那是使用 JS API。我在 AS 工作。
  • 我检查的时候用的是as3。

标签: actionscript-3 api youtube


【解决方案1】:

这些功能已被弃用。 使用

player.getVideoLoadedFraction() 

改为。

【讨论】:

    猜你喜欢
    • 2016-06-05
    • 2018-03-21
    • 1970-01-01
    • 2021-05-26
    • 2019-08-18
    • 2010-12-09
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    相关资源
    最近更新 更多