Multiple Cameras In Flex... Demystifying the Mystery
I've seen this in Flexcoders a number of times... How do you use multiple cameras within your flex application? I ran into the same issue for one of my projects, and here's what I have found. You CAN use multiple cameras within a flex application, but there are a few things that you will need to watch out for.
There is either a bug in the flash player/framework, or the documentation is inaccurate. I'm sure this has caused a number of headaches (other than those I directly experienced). The API documentation for the Camera object shows the signature of the Camera.getCamera method to be:
0: Camera A
1: Camera B
2: Camera C
According to the API documenation, using Camera.getCamera( "Camera B") should return a refference to Camera B, but it does not. I have found that using Camera.getCamera( "1") will return a valid refference to Camera B.
Below is a screenshot from a demo application that I put together that takes advantage of this trick, and will allow you to select a camera based on the string representation of the index. It shows you a list of all of the detected cameras in your system, and allows you to open display whichever one you select.

Before I post a link to actually use this application, I need to cover a few bases:
View FLV Demonstration
Launch Application
** Side note: Be sure to check out the animations that I put on the MDI manager for window tiling and cascading. :)
Questions or comments, you can contact me at andrew.trice( at )cynergysystems.com.
There is either a bug in the flash player/framework, or the documentation is inaccurate. I'm sure this has caused a number of headaches (other than those I directly experienced). The API documentation for the Camera object shows the signature of the Camera.getCamera method to be:
public static function getCamera(name:String = null):Camera
This implies that it is possible to get cameras based on the name of the camera, which one would assume to be Camera.names[ index ]. Well, this is not correct. It wouldn't work every time that I tried Camera.getCamera( Camera.names[ index ] )). After some experimentation, I realized that it would work if you pass the string representation of the camera index, rather than specifying the name of camera. For example, lets say that I have 3 cameras attached to the current system:0: Camera A
1: Camera B
2: Camera C
According to the API documenation, using Camera.getCamera( "Camera B") should return a refference to Camera B, but it does not. I have found that using Camera.getCamera( "1") will return a valid refference to Camera B.
Below is a screenshot from a demo application that I put together that takes advantage of this trick, and will allow you to select a camera based on the string representation of the index. It shows you a list of all of the detected cameras in your system, and allows you to open display whichever one you select.

Before I post a link to actually use this application, I need to cover a few bases:
- The Flex API documentation does warn against using this method. I pursued this for my own needs.
In general, you shouldn't pass a value for the name parameter; simply use getCamera() to return a reference to the default camera. By means of the Camera settings panel, the user can specify the default camera Flash should use.
-http://livedocs.macromedia.com/flex/2/langref/flash/media/Camera.html - Some cameras are detected with multiple aliases by the flash player. Trying to open a connection to one camera using multiple aliases will crash the flash player, and most likely crash your browser. One of my cameras, for instance shows up twice, as "Live! Cam Notebook Pro" and "Live! Cam Notebook Pro (VFW)". They both refer to the same physical camera. Trying to open a stream to both aliases ALWAYS crashes my browser. Opening multiple connections to the same alias does not cause a problem. I have had over 10 instances of the same camera open, without any problems.
- If you use this method, do not try to swap cameras on a Video object instance. Create a new Video object and attach the camera to it. It has been my experience that attempting to swap the source camera on an existing Video object will crash the flash player and subsequently crash the user's browser.
- The physical order of camera connections on your machine can make a difference. In one case on my laptop, I had Camera A attached at USB port 1 and Camera B attached at USB port 2. I could only get images from Camera A, not from Camera B. I swapped the USB ports for the 2 cameras, and then I could get images from both. Although, I did not have this problem on my desktop computer.
View FLV Demonstration
Launch Application
** Side note: Be sure to check out the animations that I put on the MDI manager for window tiling and cascading. :)
Questions or comments, you can contact me at andrew.trice( at )cynergysystems.com.





1 Comments:
Gah, THANK YOU!
Post a Comment
<< Home