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

查看:32
本文介绍了在 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 ----------------EDIT

我试过这个代码:

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


为什么不使用 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).

无论如何,我只是尝试了下面的这段代码,它适用于 AIR 桌面应用程序.
也许您可以将其用作起点...

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天全站免登陆