The following example shows how you can display a FLV file in a Flex application using the NetConnection, NetStream, and Video classes, as well as how to use the onMetaData and onCuePoint event handlers to handle video meta data and cue points.
<?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:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();"> <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); ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv"); 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:Application>
View source is enabled in the following example.



{ 10 comments… read them below or add one }
When I try to replace the video source http…. for an rtmpe/rtmp it doesn’t work. Why?
Thanks Peter for a nice and simple example,
i was just wondering if flex can handle any other streams which are not in .flv formats like the audio streaming links , or streaming audio and video content from a radio station streams
much like the .asx, .asf files .
may be the Flex Media Server and Encoder can help me stream such content but is there any other way to stream such content.
i even checked with OSMF it doesnt seem to support it as well.
i’ll appreciate your help
Thanks,
Lisa
So, videodisplay is depricated in flex 4. How do you do this with videoplayer?
i want information about flex
This is a a very simply way to done it. this way is so nice
Error loading the demo:
Severity and Description Path Resource Location Creation Time Id
unable to open ‘C:….\Flex Builder 3\NetConnection_NetStream_Video_test\libs’
NetConnection_NetStream_Video_test Unknown 1267650308296 39
Do I need Flash CS4 for this or is there a .swc I need to download somewhere?
Thanks in advance!
@GJHDigital,
No, I just copy/pasted the code into an existing project and it worked fine. If you imported the code via the ZIP file, you may have to double check that your project has a /libs/ folder. I think a few of these earlier ZIP files had a problem where the /libs/ folder wasn’t exporting since it was empty.
Peter
how to coonect video files into a flex
hey,
it’s allright when do we want to use VideoDisplay class instead,
see this post here!
I have created a flex application. When i play a file in my application it doesnt support full screen and on top of that the you-tube player is separated from flex video player. So both work as seperate players. What do you suggest me to do???