大家好日子。
如果条件为真,我需要在flash中循环一个flv文件。
所以我尝试添加一个监听器,但id不起作用..代码如下:
textBox.addEventListener(FocusEvent.FOCUS_IN, focusInListener);
var connection:NetConnection = new NetConnection();
var stream:NetStream;
var video:
Video = new Video(200, 200);
var metaObj:Object = new Object();
function onMetaData(data:Object):void {
}
var checkvid=0;
connection.connect(null);
stream = new NetStream(connection);
stream.client = metaObj;
metaObj.onMetaData = onMetaData;
video.attachNetStream(stream);
addChild(video);
stream.play("Mann ft. 50 Cent - Buzzin 2010-(mrsjs).flv");
video.x = 0;
video.y = 40;
textBox.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent)
{
if(event.charCode == 13) // if the key is ENTER
{
switch (textBox.text)
{
case "1":
stream.play("m1.flv");
checkvid=0;
// Note from Slomojo - You probably wanted a break; here.
case "2":
stream.play("m2.flv");
checkvid=1;
break;
case "3":
stream.play("m3.flv");
checkvid=0;
break;
}
}
}
var listener:Object = new Object();
listener.complete = function():Void {
stream.seek(0);
stream.play();
}
stream.addEventListener("complete", listener);
任何想法都表示赞赏。谢谢。
答案 0 :(得分:1)
NetStream
不会触发complete
事件,并且您正在错误地执行侦听器对象,您使用NetStream
的直接回调函数
基本上,你听onStatus
- 给它回拨一个...即:
stream_ns.onStatus = function(infoObject:Object) {
trace("NetStream.onStatus called: ("+getTimer()+" ms)");
for (var prop in infoObject) {
trace("\t"+prop+":\t"+infoObject[prop]);
}
};
您想要的信息位于infoObject
。
答案 1 :(得分:0)
我建议这个解决方案:
var stream_ns:NetStream ...
stream_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
...
stream_ns.play("video.flv");
function netStatusHandler(p_evt:NetStatusEvent):void {
if (p_evt.info.code == "NetStream.FileStructureInvalid") {
trace("The MP4's file structure is invalid.");
}
else if (p_evt.info.code == "NetStream.NoSupportedTrackFound") {
trace("The MP4 doesn't contain any supported tracks");
}
else if (p_evt.info.code == "NetStream.Play.Stop") {
trace("final of video");
repeatMethod();
}
}
所以,你需要实现repeadMethod,这可以是:
function repeatMethod():void {
stream_ns.play("video.flv");
}