3
votes

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?

2
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
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
Please share error message. SWFLoader is supported in almost all SW using AS3 for development help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/… - Imran
@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
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 '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

2 Answers

1
votes

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

-2
votes

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.