【问题标题】:Play a youtube video inside an AIR app (AS3)在 AIR 应用程序 (AS3) 中播放 youtube 视频
【发布时间】:2016-02-29 08:25:10
【问题描述】:

我想知道是否可以使用 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 页面)。

【问题讨论】:

  • 显示您尝试过但不起作用的代码...有人可以为您仔细检查。

标签: android actionscript-3 youtube air


【解决方案1】:

编辑:

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

使用此链接格式:

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

例如,选择如下格式:
https://www.youtube.com/v/hFupHx5G44s - 使用/v/ 获取 SWF 版本 https://www.youtube.com/embed/hFupHx5G44s - 使用 /embed/ 获取 HTML5 版本

适用于 ANDROID AIR 应用程序。

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

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


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


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

YouTube AS3 API 被弃用可能意味着您无法创建自己的用户界面或使用搜索等功能。您可以轻松地重新创建搜索功能(将“搜索结果”源加载到字符串中并通过解析源代码提取链接)。

无论如何,我只是在下面尝试了这段代码,它适用于 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

【讨论】:

  • 你知道为什么我在输出中出现这个错误:安全沙箱违规
  • 完整输出:*** Security Sandbox Violation *** SecurityDomain 'https://s.ytimg.com/yts/swfbin/player-vflvipWo9/watch_as3.swf' tried to access incompatible context 'app:/cine.swf' The YouTube AS3 Player API will be disabled on January 27, 2016. See https://developers.google.com/youtube/flash_api_reference Warning: Domain i.ytimg.com does not explicitly specify a meta-policy, but Content-Type of policy file https://i.ytimg.com/crossdomain.xml is 'text/x-cross-domain-policy'. Applying meta-policy 'by-content-type'.
  • 您的发布设置中是否勾选了“桌面”和“扩展桌面”?还勾选了“Windows 安装程序 (.exe)”?然后使用 .exe 文件(而不是通常的 .air 文件)安装应用程序。否则编辑您的问题。告诉我你给出这个错误的代码和视频链接。
  • 适用于 ANDROID AIR 应用程序。
  • 如果 Flash 仍然存在跨域问题,请使用url = "https://www.youtube.com/embed/hFupHx5G44s"; 尝试 HTML5 播放器
【解决方案2】:

您看过 My Flash Labs 的视频播放器 ANE 吗?

http://www.myflashlabs.com/product/video-player-ane-adobe-air-native-extension/

【讨论】:

    猜你喜欢
    • 2011-11-16
    • 2012-04-05
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2012-11-10
    • 2018-08-06
    相关资源
    最近更新 更多