转载http://hi.baidu.com/udking_love/blog/item/3bd737d1b9a525d4572c84cc.html
在Flex中利用NetConnection, NetStream和Video类显示video文件
2009年02月09日 星期一 下午 10:25
下 面的例子说明了利用NetConnection, NetStream和Video类,如何在Flex应用中显示一个FLV文件,以及如何使用onMetaData和onCuePoint事件处理视频数据 (video meta data)和提示点(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(); " 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 ) ;
- 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>
具体效果参见原文地址: