Skip to main content
Participating Frequently
July 27, 2012
Question

Youtube AS3 API for Android Mobile on Flash CS6

  • July 27, 2012
  • 2 replies
  • 8446 views

Is it possible, any working examples for Android mobile on flash cs6? 

I have scoured the net, but only have found non mobile AS3 examples..

This topic has been closed for replies.

2 replies

October 13, 2014

Hi,

These implementations are not working on Android. The video is presented flipped and is not positioned correctly. Any ideas and suggestions?

Nimisha1
Participating Frequently
July 30, 2012

You can find help from here:

Youtube player api reference: https://developers.google.com/youtube/flash_api_reference

Youtube data api reference: http://blog.martinlegris.com/2008/02/19/youtube-data-api-as3-first-tutorial/

I have a flex mobile app which uses youtube apis , if you need more help then feel free to ask .

-Nimisha

Gustine12Author
Participating Frequently
July 30, 2012

Hi Nimisha,

Flex same as Flash? Am trying to test this on Flash CS6... anyway.. here's the code am trying to test...

Problem am getting is that it works fine on AS3 itself, but once tested on Air for Android I get the

sandbox access errors which you can see on second table..

Thanks for responding..

Simple Chromeless Youtube

import flash.system.Security;

Security.allowInsecureDomain("*");

Security.allowDomain("*");

// This will hold the API player instance once it is initialized.

var player:Object;

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));

function onLoaderInit(event:Event):void {

    addChild(loader);

          loader.content.addEventListener("onReady", onPlayerReady);

    loader.content.addEventListener("onError", onPlayerError);

    loader.content.addEventListener("onStateChange", onPlayerStateChange);

    loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);

}

function onPlayerReady(event:Event):void {

    // Event.data contains the event parameter, which is the Player API ID

    trace("player ready:", Object(event).data);

    // Once this event has been dispatched by the player, we can use

    // cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl

    // to load a particular YouTube video.

   player = loader.content;

   player.loadVideoById("zlfKdbWwruY");

   player.setSize(640, 360);

}

function onPlayerError(event:Event):void {

    // Event.data contains the event parameter, which is the error code

    trace("player error:", Object(event).data);

}

function onPlayerStateChange(event:Event):void {

    // Event.data contains the event parameter, which is the new player state

    trace("player state:", Object(event).data);

}

function onVideoPlaybackQualityChange(event:Event):void {

    // Event.data contains the event parameter, which is the new video quality

    trace("video quality:", Object(event).data);

}

Sandbox Errors

[SWF] youtube_Scene%201.swf - 3536 bytes after decompression

SecurityError: Error #3207: Application-sandbox content cannot access this feature.

          at flash.system::Security$/allowInsecureDomain()

          at youtube_Scene1_fla::MainTimeline/frame1()[youtube_Scene1_fla.MainTimeline::frame1:5]

          at runtime::ContentPlayer/loadInitialContent()

          at runtime::ContentPlayer/playRawContent()

          at runtime::ContentPlayer/playContent()

          at runtime::AppRunner/run()

          at ADLAppEntry/run()

          at global/runtime::ADLEntry()

[UnloadSWF] youtube_Scene%201.swf

Test Movie terminated.

Nimisha1
Participating Frequently
July 31, 2012

Hi Gustine,

Yes the flex is same as flash. I have developed an iOS mobile AS application which plays  youtube videos with the help of stagewebview .With the player api of Youtube I also use to get File reference errors and security errors. Can you please try following code in your app and please tell if it works :

import flash.media.StageWebView;

public var wt:uint;

public var ht:uint ;

public var webview:StageWebView ;

public var rect:Rectangle;

public var url:String;

url = "http://www.youtube.com/watch?v=" + video.id;

trace(url);

wt = this.stage.stageWidth;

ht= this.stage.stageHeight;

webview = new StageWebView();

rect = new Rectangle(0,150,wt,ht/2);

webview.stage = this.stage;

webview.viewPort = rect;

webview.loadURL(url);