Youtube API Actionscript 3 和缩略图 [英] Youtube API Actionscript 3 and Thumbnails

查看:41
本文介绍了Youtube API Actionscript 3 和缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 AS3 中设置了 Youtube API - 一切都很好加载,但我想加载多个缩略图,然后显示它们,以便用户可以单击一个来观看视频,但我在做时遇到了一些麻烦这个.

I've got the Youtube API setup in AS3 - it's all loading nicely but I'd like to load multiple thumbnails and then display them so that user may click one to watch the video but I'm having a little trouble doing this.

我用于执行此操作的代码是:(其中vid_player"是我的容器对象的实例名称.

The code that I have for doing this is this: (where "vid_player" is the instance name of my container object.

   function createFeaturedButtons(vid_player:Object, featuredVideos:Array) {
   var results:Array = [];
   for each (var id:String in featuredVideos) {
    results.push(vid_player.getClickToPlayButton("BYjoERBzfNw"));
results.push(vid_player.getClickToPlayButton("oEB50roGOOg"));
    }
    return results;
   }

现在如何让它显示我的数组结果?

Now how do I get it to display my results of my Array?

推荐答案

这应该会为您提供缩略图并将它们添加到舞台显示列表中,每行之间有 5 个像素.idArray 中的项目数定义了将加载多少个按钮:

This should get you the thumbnails and add them to the stage display list in a row with 5 pixels between each. The number of items in idArray defines how many buttons will load:

var spacing:Number = 5;
var nextX:Number = 0;
var idArray:Array = [ 'BYjoERBzfNw', 'oEB50roGOOg', 'oEB50roGOOg', 'oEB50roGOOg', 'oEB50roGOOg' ];

// this call needs to be made in the onPlayerReady() method (not listed in this example but part of the youtube player initialization process)
createThumbnails( vid_player, idArray );

function createThumbnails( vid_player:Object, videoIdArray:Array )
{
    var i:int;
    var results:Array = [];

    for( i = 0; i < videoIdArray.length; i++ )
    {
        results.push( vid_player.getClickToPlayButton( videoIdArray[ i ] ) );
    }

    for( i = 0; i < results.length; i ++ )
    {
        // set whatever width and height you want the thumb to be
        results[ i ].width = 50;
        results[ i ].height = 50;

        // set its position
        results[ i ].x = nextX;
        // set the next position
        nextX += results[ i ].width + spacing;

        addChild( results[ i ] );
    }
}

当添加到成功加载播放器的代码中时,此例程的输出(使用我自己的视频 ID)如下所示(我对所有 5 个拇指使用相同的 ID):

the output from this routine, when added to code that successfully loads a player, (using my own video IDs) looks like below, (I used the same ID for all 5 thumbs):

这篇关于Youtube API Actionscript 3 和缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆