<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" click="addVideo()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.media.Video;
private var flexVideoURL:String = "D:\\娱乐\\咏春拳自学.flv";
private function addVideo():void
{
// 创建回调函数的对象
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
// 赋值给NetStream对象的属性client
var connection:NetConnection = new NetConnection();
connection.connect(null);
var stream:NetStream = new NetStream(connection);
stream.client = customClient;
var flexVideo:Video = new Video(360,240);
flexVideo.attachNetStream(stream);
stream.play(flexVideoURL);
stage.addChild(flexVideo);
}
private function metaDataHandler(infoObject:Object):void {
//获得flv文件中嵌入的描述性信息,这里获得获得总持续时间(单位:秒)
var flv_duration:Number = int(infoObject.duration);
var tM:Number = Math.floor(flv_duration/60);
var tS:Number = Math.floor(flv_duration%60);
time_txt.text="总长:"+tM+":"+tS;
}
]]>
</fx:Script>
<mx:Text id="time_txt" x="500" y="500"/>
</s:Application>