Panzercrisis
Panzercrisis

Reputation: 4750

In AS3 how can you detect if someone pulls their camera out of the USB port?

In AS3 if the SWF gets a hold of someone's camera successfully and they start streaming video across and everything, but then mid-stream, either they accidentally wiggle their camera out of the USB port, or the camera just sort of breaks down, or something else like that, how could you detect it from that user's side? I've tried using event listeners and also polling different variables every five seconds, but neither has worked; none of the public properties of Camera or its events seem to act funny at all when something like that happens. And apparently you can't just keep scanning the computer for devices (for good reason, I guess).

Is there something I'm missing here? Is there a way to detect from a user's copy of a SWF (FP or AIR, but much more importantly FP) when their camera has effectively stopped as the result of something going wrong, such as them wiggling it out of the computer by mistake? If so how? Thanks!

Upvotes: 1

Views: 714

Answers (3)

1.21 gigawatts
1.21 gigawatts

Reputation: 17830

You can check if the camera object is null as suggested by @ToddBFisher, check the Camera.names.length>0 or a few other properties of the camera instance (see the links below). But in each of them you'll want to check it at a regular interval.

Working with Cameras

Monitoring Camera Status

Upvotes: 0

Sunil D.
Sunil D.

Reputation: 18193

While you may have difficulty in detecting when the camera/microphone stops working or is deactivated, you can discern that something has gone wrong if you are publishing the video/audio to a server with a NetStream.

The NetStream has an info property which is a NetStreamInfo object. It will give you both a running total of bytes as well as a rate of bytes/second of data that the NetStream is sending to the server.

If you use the running totals, you need to periodically check the byteCount and calculate your own rate. Or you can let Flash Player do all the work and use the rates that it's calculating. In the case of recording, these values give you an indication of how much data the NetStream is receiving from the camera/microphone (and going to send to the server).

We found that we could reliably determine on the client that something had gone wrong when the rate fell below 5 kilobits/second. We used the same threshold and similar calculations on an FMS server (w/custom server side Actionscript) as well.

Upvotes: 1

ToddBFisher
ToddBFisher

Reputation: 11610

I don't recall a proper "get camera status" call you can make on demand but you can try listening for the status event and hope there's one fired on disconnect.

If you haven't already done so, on you 5 second check try: if(myCameraObject == null) assuming var myCameraObject = Camera.GetCamera();

If you can't find a better solution, consider placing a "Detect camera" button behind the camera feed. If the camera disconnects then the user would see the button and could click it to reconnect.

Upvotes: 1

Related Questions