AsyncErrorEvent:。 text=Error #2095: flash.net.NetStream 无法调用回调 onMetaData。 error=ReferenceError: Error
问题:Error #2044: 未处理的 AsyncErrorEvent:。 text=Error #2095: flash.net.NetStream 无法调用回调 onMetaData。 error=ReferenceError: Error #1069:找不到属性 onMetaData,且没有默认值。
解决方法:
加载并播放外部flv文件,想获取总时间,得如上错误提示。
// 创建回调函数的对象
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
// 赋值给NetStream对象的属性client
var my_nc:NetConnection=new NetConnection();
my_nc.connect(null);
var my_ns = new NetStream(my_nc);
my_ns.client = customClient;
my_ns.play("mov1.flv");
//onMetaData回调函数的事件
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;
}
红色为解决问题的部分
——————————————————————————————————
官方例子:
<?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>
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2009/12/15/1624486.html,如需转载请自行联系原作者