如果未找到 AS3 FLVPlayback 流,如何向舞台发送消息
我已经使用组件库成功创建了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
在您的组件实例上放置一个侦听器:
然后将您的视觉对象放在舞台上的某个位置,并在侦听器函数的流未找到区域中使用它执行您需要的操作。
Put a listener on your component instance:
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.
使用 FLVPlayback 组件的 STATE_CHANGE 事件,并检查状态是否为 CONNECTION_ERROR。
您还可以在那里检查您的视频是否已开始播放、是否已完成播放等。
下面的代码是一个示例,您可以将其用作 as3 fla 的文档类:
更新:要使上述更新的代码正常工作,请将 NetStatus 事件更改为 STATE_CHANGE 事件:
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:
UPDATE: To get your above updated code working, change the NetStatus Event to the STATE_CHANGE Event:
The FLVPlayBack component does NOT dispatch the NetStatus Event.