在 AIR 应用程序 (AS3) 中播放 youtube 视频
Play a youtube video inside an AIR app (AS3)
我想知道是否可以使用 AS3 代码在 AIR 应用程序中播放 YouTube 视频。
youtube API 似乎已被弃用...
如果有人知道方法或好的教程。
谢谢
--------------编辑
我试过这段代码:
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 页面)。
编辑:
I'd like to load only the video (not all the youtube page).
使用这种 link 格式:
url = "https://www.youtube.com/v/hFupHx5G44s";
例如,选择如下格式:
https://www.youtube.com/v/hFupHx5G44s
- 使用 /v/
获取 SWF 版本
https://www.youtube.com/embed/hFupHx5G44s
- 使用 /embed/
获得 HTML5 版本
It's for an ANDROID AIR app.
你应该在问题中提到那个细节。您可以尝试添加
Security.allowDomain("www.youtube.com");
Security.loadPolicyFile("https://www.youtube.com/crossdomain.xml");
//////////# End of Edit
为什么不使用 stageWebView
加载嵌入 (HTML5) 播放器作为网页?
YouTube AS3 API 被弃用可能意味着您无法创建自己的用户界面或使用搜索等功能。不过,您可以轻松地重新创建搜索功能(将 "search results" 源代码加载到 String 中并通过解析源代码提取 links)。
无论如何,我刚刚尝试了下面的这段代码,它适用于 AIR 桌面应用程序。
也许您可以将它用作起点...
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
您看过 My Flash Labs 的视频播放器 ANE 吗?
http://www.myflashlabs.com/product/video-player-ane-adobe-air-native-extension/
我想知道是否可以使用 AS3 代码在 AIR 应用程序中播放 YouTube 视频。
youtube API 似乎已被弃用...
如果有人知道方法或好的教程。
谢谢 --------------编辑
我试过这段代码:
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 页面)。
编辑:
I'd like to load only the video (not all the youtube page).
使用这种 link 格式:
url = "https://www.youtube.com/v/hFupHx5G44s";
例如,选择如下格式:
https://www.youtube.com/v/hFupHx5G44s
- 使用 /v/
获取 SWF 版本
https://www.youtube.com/embed/hFupHx5G44s
- 使用 /embed/
获得 HTML5 版本
It's for an ANDROID AIR app.
你应该在问题中提到那个细节。您可以尝试添加
Security.allowDomain("www.youtube.com");
Security.loadPolicyFile("https://www.youtube.com/crossdomain.xml");
//////////# End of Edit
为什么不使用 stageWebView
加载嵌入 (HTML5) 播放器作为网页?
YouTube AS3 API 被弃用可能意味着您无法创建自己的用户界面或使用搜索等功能。不过,您可以轻松地重新创建搜索功能(将 "search results" 源代码加载到 String 中并通过解析源代码提取 links)。
无论如何,我刚刚尝试了下面的这段代码,它适用于 AIR 桌面应用程序。
也许您可以将它用作起点...
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
您看过 My Flash Labs 的视频播放器 ANE 吗?
http://www.myflashlabs.com/product/video-player-ane-adobe-air-native-extension/