在AIR应用(AS3)中播放youtube视频 [英] Play a youtube video inside an AIR app (AS3)

查看:112
本文介绍了在AIR应用(AS3)中播放youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用AS3代码在AIR应用程序中播放youtube视频。

I'd like to know if it's possible to play a youtube video inside an AIR app using AS3 code.

似乎不赞成使用youtube API ...

It seems that youtube API is deprecated...

如果有人知道方法或好的教程,就可以了。

If anybody knows a way or a good tutorial.

Thx
----------------编辑

Thx ----------------EDIT

我已经尝试过这段代码:

I've tried this code :

var wt:uint;
var ht:uint ;
var webview:StageWebView ;
var rect:Rectangle;
var url:String;

url = "https://www.youtube.com/watch?v=hFupHx5G44s";

trace(url);

wt = this.stage.stageWidth;
ht = this.stage.stageHeight;

webview = new StageWebView();
rect = new Rectangle(0,300,wt,ht/2);

webview.stage = this.stage;
webview.viewPort = rect;
webview.loadURL(url);

但是它正在使用滚动条加载youtube的所有页面(youtube视频+推荐的视频..)在右边。
我只想加载视频(而不是全部youtube页面)。

But it's loading the all page of youtube (youtube video + the recommended videos..) with a scroller on the right. I'd like to load only the video (not all the youtube page).

推荐答案

编辑:


我只想加载视频(不是所有的youtube页面)。

I'd like to load only the video (not all the youtube page).

使用此链接格式:

Use this link format :

url = "https://www.youtube.com/v/hFupHx5G44s";

例如,选择以下格式:

https://www.youtube.com/v/hFupHx5G44s -使用 / v / 获取SWF版本
https://www.youtube.com/embed/hFupHx5G44s -使用 / embed / 获取HTML5版本

for example, choose a format like below :
https://www.youtube.com/v/hFupHx5G44s - use the /v/ to get a SWF version https://www.youtube.com/embed/hFupHx5G44s - use the /embed/ to get a HTML5 version


这是针对Android AIR应用程序的。

It's for an ANDROID AIR app.

您应该在问题中提到该细节。您可以尝试添加

You should have mentioned that detail in the question. You could try adding

Security.allowDomain("www.youtube.com");
Security.loadPolicyFile("https://www.youtube.com/crossdomain.xml");


//////////# End of Edit

< br>
为什么不使用 stageWebView 来将嵌入(HTML5)播放器加载为网页?


Why not use stageWebView to load the embed (HTML5) player as web page?

不推荐使用YouTube AS3 API可能意味着您无法创建自己的用户界面或使用搜索之类的功能。不过,您可以轻松地重新创建搜索功能(将搜索结果源加载到String中并通过分析源代码来提取链接)。

The YouTube AS3 API being deprecated likely means you cannot create your own user interface or use features like search. You can re-create the search function easily though (load "search results" source into String and extract links by parsing the source code).

无论如何,我只是尝试过
也许您可以将其用作起点...

Anyways, I just tried this code below and it worked for an AIR Desktop App.
Maybe you can use it as a starting point...

package  
{

import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;

import flash.events.*;
import flash.system.*;


public class Youtube_AIR_code extends MovieClip 
{
    public var YT_Loader : Loader;
    public var my_VIDEO_ID : String = "hFupHx5G44s"; //# the YouTube ID

    public function Youtube_AIR_code () 
    {
        Security.loadPolicyFile("http://www.youtube.com/crossdomain.xml");

        YT_Loader = new Loader();
        YT_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, YT_Ready );
        YT_Loader.load( new URLRequest("http://www.youtube.com/v/" + my_VIDEO_ID) );

    }

    function YT_Ready (e:Event) : void
    {
        trace("YouTube SWF :: [status] :: Loading Completed");

        //addChild(YT_Loader);

        //# Wait for Youtube Player to initialise
        YT_Loader.content.addEventListener("onReady", on_YT_PlayerLoaded );

    }

    private function on_YT_PlayerLoaded (e:Event) : void
    {
        //# Check Original Width/Height - Scale it proportionally               
        trace( "YT_Loader content Width  : " + YT_Loader.content.width );
        trace( "YT_Loader content Height : " + YT_Loader.content.height );

        //# Testing changed size and position
        YT_Loader.width = 320; YT_Loader.height = 240;
        YT_Loader.x = 30; YT_Loader.y = 100;

        addChild(YT_Loader); //# can add to stage only

    }

} //# End Public Class

} //# End Package

这篇关于在AIR应用(AS3)中播放youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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