netStream status events question using Adobe Cirrus
Basically i'll try and sum this up. I have a bunch of potential random strings for 开发者_JAVA百科recvStream.play("randomstring");
then i have a timer checking every 5 seconds on a function that runs an event listener:
recvStream.addEventListener(NetStatusEvent.NET_STATUS,
netConnectionHandler);
then im thinking in a switch statement i can use it to check if it's an active stream or not to either have it search for another stream that should be active or stop the timer and let it play.
// 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
But it really doesn't work like that. Is there something else I should be using instead of NetStream.Buffer.Empty ? Or something else all together?
I'm using Actionscript 3 in Flash CS5 and I'm using Cirrus RTMFP http://labs.adobe.com/technologies/cirrus/
I don't get why you'd have a timer check the stream, when you have a listener attached to tell you about its status:
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.
}
}
Obviously, you should also consider validating your random string's correctness before you even call recvStream.play()
- which would be cleaner than deliberately letting your NetStream fail, and not strain the network.
精彩评论