【问题标题】:Passing youtube video id from video feed to flash将 youtube 视频 ID 从视频提要传递到 Flash
【发布时间】:2010-10-21 18:55:39
【问题描述】:

我正在为我的荣誉项目开发一个 Flash Web 应用程序 (Actionscript 2.0),但在嵌入 youtube 视频时遇到了问题。基本上,用户根据所选符号选择带有特定标签的 youtube api 查询符号,然后从前 30 个视频中挑选一个随机视频。我使用以下代码进行此工作:

on (release) {
url="http://gdata.youtube.com/feeds/api/videos?q=danger+passion&orderby=published&start-index="+random(30)+"&max-results=1&v=2"
getURL(url);
}

但这只会显示一个网页,其中包含指向 youtube 视频的链接。

这是我将用作播放器基础的代码:

// create a MovieClip to load the player into
var ytplayer:MovieClip = _root.createEmptyMovieClip("ytplayer", 1);

// create a listener object for the MovieClipLoader to use
var ytPlayerLoaderListener:Object = {
onLoadInit: function() {
// When the player clip first loads, we start an interval to
// check for when the player is ready
loadInterval = setInterval(checkPlayerLoaded, 250);
}
};

var loadInterval:Number;


function checkPlayerLoaded():Void {
// once the player is ready, we can subscribe to events, or in the case of
// the chromeless player, we could load videos
if (ytplayer.isPlayerLoaded()) {
ytplayer.addEventListener("onStateChange", onPlayerStateChange);
ytplayer.addEventListener("onError", onPlayerError);
clearInterval(loadInterval);
}
}

function onPlayerStateChange(newState:Number) {
trace("New player state: "+ newState);
}

function onPlayerError(errorCode:Number) {
trace("An error occurred: "+ errorCode);
}

// create a MovieClipLoader to handle the loading of the player
var ytPlayerLoader:MovieClipLoader = new MovieClipLoader();
ytPlayerLoader.addListener(ytPlayerLoaderListener);

// load the player
ytPlayerLoader.loadClip("http://www.youtube.com/v/pv5zWaTEVkI", ytplayer);

谁能帮助我从提要中获取视频的 ID(例如:pv5zWaTEVkI)?或者如何从 Flash 发送查询,该查询将返回视频 url/id,而不是 feed 的 url。任何帮助将不胜感激,因为我很快就会介入。谢谢

【问题讨论】:

    标签: flash actionscript-2 youtube-api


    【解决方案1】:

    你得到的不是网页,而是RSS feed.

    如果您只想要 youtube 视频 ID,您可以将获得的字符串拆分为 watch?v=,并且视频字符串应由前一个字符组成,直到 '(逗号)

    href='http://www.youtube.com/watch?v=aFyfbcZqdck' /><link
    

    你可以通过拆分这个字符串来练习。

    【讨论】:

    • 感谢您这么快回答。我有点理解你的意思,但它首先将视频的 url 从 rss 反馈传回 flash。然后我可以从中提取视频ID。
    • 您可以在 actionscript 中使用 LoadVars 将 html 加载到字符串中。然后解析它。
    • 太棒了。完全不知道您可以将网页的整个 html 加载到字符串中。设法使用 String.split 来提取视频 ID。非常感谢您的帮助。
    猜你喜欢
    • 2017-04-19
    • 1970-01-01
    • 2019-02-28
    • 2011-09-27
    • 2019-10-24
    • 1970-01-01
    • 2016-09-28
    • 2013-07-02
    • 2017-08-25
    相关资源
    最近更新 更多