如果未找到 AS3 FLVPlayback 流,如何向舞台发送消息

发布于 2024-10-21 07:32:38 字数 698 浏览 0 评论 0原文

我已经使用组件库成功创建了 FLVPlayback 组件,并且它正在播放我想要的流视频。我的问题是,如果该流不在线或找不到,我将如何在舞台上显示消息以让用户知道没有活动流。

更新: 这是我的代码 -

thestream.addEventListener(NetStatusEvent.NET_STATUS, onNCStatus);
function onNCStatus(event:NetStatusEvent):void {
    trace(event.info.code)
    switch (event.info.code) {
        case "NetConnection.Connect.Success":
            trace("Success");
            break;
        case "NetStream.Play.StreamNotFound":
            trace("Stream not found");
            break;
    }   
}

仍然没有输出。该函数似乎没有被调用。但是,如果我在函数外部(在其之前)放置跟踪,我会收到响应:

trace(NetStatusEvent.NET_STATUS);

输出:

netStatus

希望这会有所帮助。

I've successfully created an FLVPlayback component using the component library and it's playing the streaming video that I want it to. My question is, if that stream is not online or cannot be found, how would I go about displaying a message on the stage to let the user know, there is no active stream.

UPDATED:
Here's my code -

thestream.addEventListener(NetStatusEvent.NET_STATUS, onNCStatus);
function onNCStatus(event:NetStatusEvent):void {
    trace(event.info.code)
    switch (event.info.code) {
        case "NetConnection.Connect.Success":
            trace("Success");
            break;
        case "NetStream.Play.StreamNotFound":
            trace("Stream not found");
            break;
    }   
}

There's no output still. It seems like the function isn't getting invoked. However, if I place a trace outside the function (before it), I get a response:

trace(NetStatusEvent.NET_STATUS);

the output:

netStatus

Hope this helps.

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

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

发布评论

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

评论(3

阳光①夏 2024-10-28 07:32:38

flvPlaybackComponent.addEventListener(*NetStatusEvent.NET_STATUS*, onNCStatus);

如果不看你的代码很难判断。首先,最好确保代码中不存在用于功能的字符串,因此您应该将字符串“netStatus”替换为 NetStatusEvent.NET_STATUS(静态常量变量)。

flvPlaybackComponent.addEventListener(*NetStatusEvent.NET_STATUS*, onNCStatus);

Difficult to tell without seeing your code. As a start, it's good practice to ensure there are never strings in your code for functionality, so you should replace the string "netStatus" with NetStatusEvent.NET_STATUS which is a static constant variable.

北恋 2024-10-28 07:32:38

在您的组件实例上放置一个侦听器:

flvPlaybackComponent.addEventListener("netStatus", onNCStatus);

function onNCStatus(event:NetStatusEvent):void {
 trace(event.info.code)
 switch (event.info.code) {
  case "NetConnection.Connect.Success":
      trace("Success");
      break;
  case "NetStream.Play.StreamNotFound":
     trace("Stream not found");
     break;
 }   
}

然后将您的视觉对象放在舞台上的某个位置,并在侦听器函数的流未找到区域中使用它执行您需要的操作。

Put a listener on your component instance:

flvPlaybackComponent.addEventListener("netStatus", onNCStatus);

function onNCStatus(event:NetStatusEvent):void {
 trace(event.info.code)
 switch (event.info.code) {
  case "NetConnection.Connect.Success":
      trace("Success");
      break;
  case "NetStream.Play.StreamNotFound":
     trace("Stream not found");
     break;
 }   
}

Then just have your visual somewhere on stage and do what you need with it within the stream not found area of the listener function.

初熏 2024-10-28 07:32:38

使用 FLVPlayback 组件的 STATE_CHANGE 事件,并检查状态是否为 CONNECTION_ERROR。
您还可以在那里检查您的视频是否已开始播放、是否已完成播放等。

下面的代码是一个示例,您可以将其用作 as3 fla 的文档类:

package
{
    import flash.display.Sprite;
    import fl.video.FLVPlayback;
    import fl.video.VideoEvent;
    import fl.video.VideoState;
    public class Player extends Sprite
    {
        public var playback:FLVPlayback;

        public function Player()
        {
            playback.addEventListener(VideoEvent.STATE_CHANGE, onStateChange);
        }

        private function onStateChange(ev:VideoEvent):void
        {
            if (ev.state == VideoState.CONNECTION_ERROR)
            {
                trace("could not load video");
            }
        }
    }
}

更新:要使上述更新的代码正常工作,请将 NetStatus 事件更改为 STATE_CHANGE 事件:

thestream.addEventListener(VideoEvent.STATE_CHANGE, onNCStatus);
   function onNCStatus(event:VideoEvent):void {
       trace(event.info.code)
       switch (event.state) {
           case VideoState.CONNECTION_ERROR:
               trace("Stream not found/Could not connect to stream");
               break;
       }   
   }

FLVPlayBack 组件不会调度 NetStatus 事件。

Use the STATE_CHANGE Event of the FLVPlayback Component, and check for the state if it is an CONNECTION_ERROR.
You also can check in there if your video has started playing, if it has finished playing and so on.

The below code is a sample that you can use as documentclass for an as3 fla:

package
{
    import flash.display.Sprite;
    import fl.video.FLVPlayback;
    import fl.video.VideoEvent;
    import fl.video.VideoState;
    public class Player extends Sprite
    {
        public var playback:FLVPlayback;

        public function Player()
        {
            playback.addEventListener(VideoEvent.STATE_CHANGE, onStateChange);
        }

        private function onStateChange(ev:VideoEvent):void
        {
            if (ev.state == VideoState.CONNECTION_ERROR)
            {
                trace("could not load video");
            }
        }
    }
}

UPDATE: To get your above updated code working, change the NetStatus Event to the STATE_CHANGE Event:

thestream.addEventListener(VideoEvent.STATE_CHANGE, onNCStatus);
   function onNCStatus(event:VideoEvent):void {
       trace(event.info.code)
       switch (event.state) {
           case VideoState.CONNECTION_ERROR:
               trace("Stream not found/Could not connect to stream");
               break;
       }   
   }

The FLVPlayBack component does NOT dispatch the NetStatus Event.

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