3

Is there any way to embed YouTube video/video player into Android Flex AIR Mobile application?

I tried to use SWFLoader(...) but since its MX library class only works on the desktop runtime environment, but fails to work on actual Android device when debugging the application. Any ideas?

Maybe it's possible to embed HTML that contain YouTube video into some Flex media container like TextArea or something?

mdb
  • 52,000
  • 11
  • 64
  • 62
topsky
  • 199
  • 3
  • 12
  • For mobile apps, why do you want to embed? Just link to the content and the device should automagically handle the video; either in the browser or w/ the native video player app. – JeffryHouser Apr 20 '11 at 15:38
  • Do you mean just add html link to let say TextArea component, and let user click on it if he want to see video? – topsky Apr 20 '11 at 16:08
  • Please share error message. SWFLoader is supported in almost all SW using AS3 for development http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/SWFLoader.html – Imran Apr 20 '11 at 16:32
  • 2
    @user717412 I'm not sure I'd add an HTML Link in a TextArea component. I'd probably use a button of sorts that when the user clicks (Touches) it uses NavigateToURL to load the video; and then Android should handle that URL. – JeffryHouser Apr 20 '11 at 17:04
  • I haven't had a chance to try this out yet, my old Flex burrito went bad so I'm downloading again (still 1hr left). I imagine it would be possible, be sure you're adding the Security.allowDomain("www.youtube.com") call since it'll load data from there, also I'd assume the device would have to actually have Flash player installed, since it actually creates an apk for the AIR app and doesn't run in the flash player I can see how this issue could arise. Furthermore I know this won't work if packaged for iPhone because of the lack of Flash support, similar woes on the GMaps Flash API forum. – shaunhusain Apr 20 '11 at 18:23
  • 1
    I use "SWFLoader" tag and then use call in script block to loader.load(youtube_url). When running on device I recieve following message: *** Security Sandbox Violation *** SecurityDomain 'http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1' tried to access incompatible context 'app:/Main.swf'. And then I add Security.allowDomain("*") I receive exception: "SecurityError: Error #3207: Application-sandbox content cannot access this feature." So, in both cases I have an error. – topsky Apr 20 '11 at 23:29

2 Answers2

1

here you go, sir:

        protected var loader:Loader = new Loader();
        [Bindable]
        protected var player:Object;

        protected function view1_creationCompleteHandler(event:FlexEvent):void
        {
            trace("init")
            Security.loadPolicyFile("http://www.youtube.com/crossdomain.xml");
            loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

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

        protected function onLoaderInit(event:Event):void {
            trace("onLoader")
            loader.content.addEventListener("onReady", onPlayerReady);
            loader.content.addEventListener("onError", onPlayerError);
            loader.content.addEventListener("onStateChange", onPlayerStateChange);
            loader.content.addEventListener("onPlaybackQualityChange", 
                onVideoPlaybackQualityChange);
        }

        public function loadVideo(id:String):void{
            player.cueVideoByUrl(id);
            trace("playing",id)
            player.playVideo();
        }

        protected function onPlayerReady(event:Event):void {
            player = loader.content;
            //player.setSize(240, 210);

            swfLoader.autoLoad = true;
            swfLoader.scaleContent = true;
            swfLoader.maintainAspectRatio = true;
            swfLoader.load(player);
            trace("theLo" ,String(data))
            loadVideo(String(data))// kell az 1-es feladathoz itt
        }

        protected function swfLoader_securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityerror",event);
        }

        protected function onPlayerError(event:Event):void {
            trace("player error:");
        }

        protected function onPlayerStateChange(event:Event):void {
            trace("player state:", Object(event).data);
        }

        protected function onVideoPlaybackQualityChange(event:Event):void {
            trace("video quality:", Object(event).data);
        }

    ]]>
</fx:Script>
<s:SWFLoader id="swfLoader" x="0" y="64" width="100%" height="100%"
             securityError="swfLoader_securityErrorHandler(event)"/>

as you see, you dont need to embed html. you can add sliders and buttons as well.. for more information, see youtube actionscript api: https://developers.google.com/youtube/flash_api_reference

csomakk
  • 5,369
  • 1
  • 29
  • 34
-2

I don't know what kind of problems you're having embedding the playing in Flex. It's very possible and it shouldn't be that hard. Please refer to this example to implement it yourself.

P.S. I found that example by doing a google search. You should try it out sometime.

andrewpthorp
  • 4,998
  • 8
  • 35
  • 56
J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • Ofcouse I know about existance of Tour de flex and Cloud API, but pay attention that I asked abouit AIR Mobile application whose libs are limited. And SWFLoader is not supported. – topsky Apr 20 '11 at 16:10
  • Er, what? Air libs are limited? Air libs are **added** on top of Flex's libs, hence [SWFLoader](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/SWFLoader.html) is supported (as mentioned in the link, as of Air runtime 1.1). It seems you're not importing the Flex library, which is a bigger problem in itself. You can remove that -1 now... – J_A_X Apr 20 '11 at 16:51
  • I tried to do this with Vimeo at one point. If I remember correctly, the SWFLoader in the mobile SDK will not allow you to load cross-domain SWF files. I tried to get around it... tried some hacking even... but I never got it working. @J_A_X: Have you been successful doing this with the mobile SDK? – Brian Genisio Apr 20 '11 at 17:23
  • Can't say I've tried to get a swf from another domain into my mobile apps, but I know they work if you're using the `Embed` directive. – J_A_X Apr 20 '11 at 17:30
  • 2
    BTW, I added the -1 for the snarky PS you added. If you remove it, I'd be happy to rescind my down-vote. :) – Brian Genisio Apr 20 '11 at 18:19
  • Snark is needed for the world to go forward. How is it that it's fine to just ask instead of actually doing research first because legitimately being stuck and then asking for help. You're now encouraging him to do so. – J_A_X Apr 20 '11 at 18:27
  • 1
    @J_A_X but I haven't seen any evidence from the OP that he didn't already do his research. He tried SWFLoader but it didn't work for him, thus the question. He was asking about doing this in the mobile space as he implied it was working on the desktop. The google search jab was out of line, IMO. Were the question "Hows can Iz embed UTube", I'd think the snark was appropriate. (Not sure who gave you the second -1, though) – Brian Genisio Apr 20 '11 at 18:43