1

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

It seems that youtube API is deprecated...

If anybody knows a way or a good tutorial.

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);

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).

VC.One
  • 14,790
  • 4
  • 25
  • 57
user5870211
  • 103
  • 8

2 Answers2

0

Edit :

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

Use this link format :

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

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

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


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

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
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Do you know why I've got this error in the output : Security Sandbox Violation – user5870211 Mar 01 '16 at 00:43
  • Full output : `*** 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'.` – user5870211 Mar 01 '16 at 00:43
  • Do you have "Desktop" & "extended Desktop" both ticked in your Publish settings? Also "Windows installer (.exe)" is ticked?. Then install the app using the **.exe** file (instead of usual **.air** file). Otherwise edit your question. Show me the code and video link you have giving this error. – VC.One Mar 01 '16 at 00:58
  • It's for an ANDROID AIR app. – user5870211 Mar 01 '16 at 00:59
  • If Flash still gives crossdomain issue then try the HTML5 player by using `url = "https://www.youtube.com/embed/hFupHx5G44s";` – VC.One Mar 01 '16 at 01:26
  • It's working with url. It's still saying `security Sandbox Violation` but the video is displayed. – user5870211 Mar 01 '16 at 01:41
  • Is it possible to control the height and width of `YT_Loader` ? (`YT_Loader.heigth` is not working. If I put this `YT_Loader.height = 200;` it doesn't display the video) – user5870211 Mar 01 '16 at 01:55
  • @user5870211 `YT_Loader` just gets YT link (data), now that link will also begin to load the YT player, when it completes you can change position and size. I've re-edited the code with a working example. – VC.One Mar 01 '16 at 14:56
0

Have you seen the Video Player ANE from My Flash Labs?

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

crooksy88
  • 3,849
  • 1
  • 24
  • 30