I'm building a video chat in flash and everything works really well, except for the part where I'm trying to detect if the other user is sending a working video stream.
There's a couple of reasons why the other user isn't sending video.
So how do I detect if the stream I receive from the other user is a black stream(because of the reasons above) using the NetStream class?
The closest thing I have came up with is by adding a timer that polls the currentFps() function from the stream I receive from the other user. But so far this seems pretty unreliable because I might get currentFps() == 0
and show an error because of this even though I actually got video from the stream in some cases. The reason for this is because I poll the API every 4 seconds for the currentFPS function and let's say at 00:00:04 I get "no video" according to the poll but at 00:00:05 the video kicks in, and therefor I need to wait until the next tick until the error message disappears
This is what my current poll looks like
function subscribingStatusPoll(e:TimerEvent):void {
if (subscribingStream.currentFPS == 0){
error.text = "No video found from the other user..."
} else {
error.text = "";
}
}
This is the only hack I that I can come up with to detect this, but this is unreliable and I actually would prefer a way to instantly detect if the stream I receive got a working video attached to it without this ugly poll.
While I would agree with not sending a "blank" stream from the server-side, you may not have access to the server-side and thus it would not apply to your situation. On the client-side you could grab a frame from the stream at an interval and check for changes or just look at the timestamps (look for an increase over time). These options may seem hack-ish but they should definitely work in Flash.
If I had to develop this myself, I would start with this edge detection code and replace the webcam grab with a frame grab from the playing stream.