1

基本上我会试着总结一下。我有一堆潜在的随机字符串 recvStream.play("randomstring");

然后我有一个计时器每 5 秒检查一次运行事件侦听器的函数:

recvStream.addEventListener(NetStatusEvent.NET_STATUS,
    netConnectionHandler);

然后我在一个 switch 语句中思考,我可以使用它来检查它是否是活动流,或者让它搜索另一个应该处于活动状态的流,或者停止计时器并让它播放。

    // i was thinking this would verify it's playing and then that's it
         case "NetStream.Play.Start" :
            trace("ITS PLAYING YOU SHOULD SEE SOMETHING");
            timer.stop();
                        break;

         // i was thinking i could use this to see if the string is nothing then the timer would run again
         case "NetStream.Buffer.Empty" :
            trace("THE BUFFER IS EMPTY KEEP LOOKING");
                        //code to look again
            break;

//I also tried NetStream.Play.StreamNotFound instead of NetStream.Buffer.Empty didn't work either

但它真的不是那样工作的。我应该使用其他东西来代替 NetStream.Buffer.Empty 吗?还是其他什么都在一起?

我在 Flash CS5 中使用 Actionscript 3,我正在使用 Cirrus RTMFP http://labs.adobe.com/technologies/cirrus/

4

1 回答 1

0

我不明白为什么当你连接了一个监听器来告诉你它的状态时,你会有一个计时器检查流:

recvStream.addEventListener(NetStatusEvent.NET_STATUS,
    netStatusHandler);

// some code

private function netStatusHandler (ev:NetStatusEvent) : void {

    if (ev.info.level == "error") {
        trace ("Something went wrong. Try again!");
        // call restart method here
        return;
    }

    switch (ev.info.code) {
        case "NetStream.Play.Start" :
            trace("IT'S PLAYING YOU SHOULD SEE SOMETHING");
            break;

        case "NetStream.Buffer.Empty" :
            trace("THE BUFFER IS NOW EMPTY.");
            break;

        // ... any other netstatus events you want to react upon.
    }
}

显然,您还应该考虑在调用之前recvStream.play()验证您的随机字符串的正确性——这比故意让您的 NetStream 失败更干净,并且不会使网络紧张。

于 2011-01-27T08:00:54.023 回答