我想知道是否可以使用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 = "www.youtube/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 = "www.youtube/v/hFupHx5G44s";例如,选择以下格式: www.youtube/v/hFupHx5G44s -使用 / v / 获取SWF版本 www.youtube/embed/hFupHx5G44s -使用 / embed / 获取HTML5版本
for example, choose a format like below : www.youtube/v/hFupHx5G44s - use the /v/ to get a SWF version www.youtube/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"); Security.loadPolicyFile("www.youtube/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).
无论如何,我只是尝试过也许您可以将其用作起点...
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.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("www.youtube/crossdomain.xml"); YT_Loader = new Loader(); YT_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, YT_Ready ); YT_Loader.load( new URLRequest("www.youtube/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视频
发布评论