动作脚本、flash、ns - 如果条件为真则循环播放 flv

发布于 2024-10-17 11:30:12 字数 1427 浏览 8 评论 0原文

祝大家美好的一天。

如果条件成立,我需要在闪存中循环播放 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);

任何想法都表示赞赏。谢谢。

Good day to all.

I need to loop a flv file in flash if a condition is true.

So I tryed to add a listener but id doesn't work.. Code below:

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);

Any idea is appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁轨上的流浪者 2024-10-24 11:30:12

NetStream 不会触发 complete 事件,并且您错误地执行了侦听器对象,您对 NetStream 使用直接回调函数,

请参阅此处:http://livedocs.adobe.com /flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#event:onPlayStatus

基本上,您监听 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 中。

NetStream doesn't fire a complete event, and you're doing the listener object incorrectly, you use a direct callback function for the NetStream

See here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#event:onPlayStatus

Basically, you listen to onStatus - assign a callback to it... ie:

stream_ns.onStatus = function(infoObject:Object) {
        trace("NetStream.onStatus called: ("+getTimer()+" ms)");
        for (var prop in infoObject) {
            trace("\t"+prop+":\t"+infoObject[prop]);
        }
};

The information you want is in the infoObject.

脸赞 2024-10-24 11:30:12

我建议这个解决方案:

    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");
    }

I suggest this solution:

    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();
        }
    }

So, you need to implement the repeadMethod, this can be as:

    function repeatMethod():void {
          stream_ns.play("video.flv");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文