Play a video file in AIR

1 view
Skip to first unread message

rails developer

unread,
May 27, 2008, 2:18:24 AM5/27/08
to Chennai Flex User Group
hi friends,
can anybody let me knw how to display a video file(.flv) in an AIR
application.



Thanks in Advance

Rajan M

unread,
May 27, 2008, 8:24:40 AM5/27/08
to chennai-fle...@googlegroups.com
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/ -->
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            import mx.utils.ObjectUtil;

            private var nc:NetConnection;
            private var ns:NetStream;
            private var video:Video;
            private var meta:Object;

            private function init():void {
                var nsClient:Object = {};
                nsClient.onMetaData = ns_onMetaData;
                nsClient.onCuePoint = ns_onCuePoint; 

                nc = new NetConnection();
                nc.connect(null);

                ns = new NetStream(nc);
               
         //here give flv file name -- whole path
              ns.play("flv/testing1.flv");
             
          
             
             
               
                //ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");
                //ns.play("http://www.youtube.com/v/qxFywcdbdH0&hl=en");
                ns.client = nsClient;

                video = new Video();
                video.attachNetStream(ns);
                uic.addChild(video);
            }

            private function ns_onMetaData(item:Object):void {
                trace("meta");
                meta = item;
                // Resize Video object to same size as meta data.
                video.width = item.width;
                video.height = item.height;
                // Resize UIComponent to same size as Video object.
                uic.width = video.width;
                uic.height = video.height;
                panel.title = "framerate: " + item.framerate;
                panel.visible = true;
                trace(ObjectUtil.toString(item));
            }

            private function ns_onCuePoint(item:Object):void {
                trace("cue");
            }
        ]]>
    </mx:Script>

    <mx:Panel id="panel" visible="false">
        <mx:UIComponent id="uic" />
        <mx:ControlBar>
            <mx:Button label="Play/Pause" click="ns.togglePause();" />
            <mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
        </mx:ControlBar>
    </mx:Panel>

</mx:WindowedApplication >
--
Rajan M
Mobile:09740572982

Natchiar V

unread,
May 28, 2008, 12:06:15 AM5/28/08
to chennai-fle...@googlegroups.com
hey thanks for ur reply.wen i execute the code i can see the video display component being display bt my flv file is nt playing.:(
Also is there anything issue abt the version of the flash player and version of the AIR.
Bt the version of the flash player i am using supports video display in browser bt nt in AIR.

Natchiar V

unread,
May 28, 2008, 12:13:19 AM5/28/08
to chennai-fle...@googlegroups.com
for the code given below i get the following error:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound
    at PDFReader/init()[C:\flexiblerails\current\PDFReader\app\flex\PDFReader.mxml:26]
    at PDFReader/___PDFReader_WindowedApplication1_creationComplete()[C:\flexiblerails\current\PDFReader\app\flex\PDFReader.mxml:7]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:9051]
    at mx.core::UIComponent/set initialized()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:1167]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:698]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.core::UIComponent/callLaterDispatcher2()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8460]
    at mx.core::UIComponent/callLaterDispatcher()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8403]
=====================================================================================================================================


bt for the following code i can see a video display component alone with no flv file being displayed.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FBFAFC, #F3F3F4]">
<mx:Script>
<![CDATA[
import flash.filesystem.File;
import mx.events.FileEvent;

/*****************************
Create a file object and point it to documentsDirectory.
It is the My Documents directory in case of Windows and
Documents subdirectory of the user directory in case of Mac OS.
******************************/

private var file:File = File.documentsDirectory;

/*****************************
browseForOpen method opens up a browse directory dialog
box to open a file from My Documents directory
(Documents directory in case of Mac OS) for file browsing
and upon selection of a file onSelect method is called.
******************************/

private function fileOpen():void {
file.browseForOpen("Select a file");
file.addEventListener(Event.SELECT, onSelect);
}
/**********************************
onSelect method assigns the url property of the file object to the
variable vUrl and the name property to the variable vName as a string.

**********************************/
[Bindable]
private var vUrl:String;
[Bindable]
private var vName:String;
private function onSelect(event:Event):void {
vUrl = file.url;
vName = file.name;
myVideo.play();
timer.visible=true
}

private function closeVid():void {
myVideo.stop();
timer.visible=false;
vidName.visible=false;
}

]]>
</mx:Script>
<mx:VideoDisplay x="70" y="26" width="379" height="234" id="myVideo" source="{vUrl}"/>
<mx:Button click="fileOpen()" label="Open" x="70" y="289"/>
<mx:Button x="134" y="289" label="Close" click="closeVid()"/>
<mx:Label x="90" y="10" text="{vName}" id="vidName" fontSize="10" fontWeight="bold" color="#0E5B87"/>
<mx:Label x="210" y="291" id="timer" text="{myVideo.playheadTime}/{myVideo.totalTime}" visible="false"/>
</mx:WindowedApplication>


thanks in advance
Reply all
Reply to author
Forward
0 new messages