video加载出错
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" click="addVideo()">
<mx:Script>
<![CDATA[
public var videoURL:String="http://www.tudou.com/l/wh18hw40H_0";
public function addVideo():void{
var connection:NetConnection=new NetConnection();
connection.connect(null);
var stream:NetStream=new NetStream(connection);
var flexVideo:Video=new Video(320,240);
flexVideo.attachNetStream(stream);
stream.play(videoURL);
stage.addChild(flexVideo);
}
]]>
</mx:Script>
</mx:Application>
报错,如下:
Error #2044: 未处理的 NetStatusEvent:。 level=error, code=NetStream.Play.StreamNotFound
at videoStu/addVideo()[D:\FlexProject\studyExample\src\videoStu.mxml:9]
at videoStu/___videoStu_Application1_click()[D:\FlexProject\studyExample\src\videoStu.mxml:2]
请问是什么原因??
[解决办法]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[
public var videoURL:String="a.flv";
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(videoURL);
ns.client=nsClient;
video=new Video();
video.attachNetStream(ns);
v_Display.addChild(video);
}
private function ns_onMetaData(item:Object):void
{
trace("meta");
meta=item;
video.width=item.width;
video.height=item.height;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void
{
trace("cue");
}
]]>
</mx:Script>
<mx:VideoDisplay id="v_Display"
width="320"
height="240"/>
</mx:Application>
看帮助做了一个.
如果是swf 文件,就会出那个错误.
// 创建回调函数的对象
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
就是这个地方.
另外:
stage.addChild(flexVideo);
好像也有问题,
Video 不会换成UIComponent对象的.
必须同VideoDisplay 才能加载到Application 中.