Camera object for FCS Programming

Source: Internet
Author: User
This section describes how to use a camera object, including using optimization, setting the appropriate bandwidth, and using a camera for multiple applications.
The camera object allows you to capture a video from a camera and append it to any MC. When you use the flashmx COM server, you can also transmit and display the video between online objects, even the captured video is recorded. With this feature, you can develop applications such as video conferencing and video chat. You can also use a camera object instead of a server. For example, you can capture your video and attach it to a MC.
Common attributes of camera:

  1. Bandwidth: the maximum number of bytes transmitted per second.
  2. Current FPS value transmitted by currentfps
  3. FPS value set by the FPS setmode Method
  4. Name the current camera name
  5. An array of video capturing devices available for names
  6. Index indicates the index value of a video device.
  7. Keyframeinterval key frame Interval
  8. Whether the loopback compresses the image
  9. Motionlevel Sensitivity 0 ~ 100 the higher the value, the slower the action.
  10. Width: The image width.
  11. Height the Image Height
  12. Quality: The image quality transmitted is 0 ~ 100
  13. Whether the muted client allows flash to access the local camera

To create a camera object, run the following code: 1: mycamera = camera. Get ();
2: // if you have multiple video devices, use index to specify the device.
3: mycamera = camera. Get (INDEX );
4:

If you access different domains, a window will pop up asking the user to confirm or reject the use:


The onstatus event is triggered when the user responds to the pop-up window. For details, refer to the muted parameter.
Of course, you can also remember the user's choice and right-click to see the setting window


In this window, select allow and remember. The Confirmation window will not pop up next time.
A more advanced example is the pop-up device selection window for users to select: 1: camarray = camera. names;
2: If (camarray. Length = 1 ){
3: camera. Get ();
4 :}
5: else
6: system. showsettings (3); // The video setting window is displayed.
7: camera. Get ();

The arckid of flashcomguru provides a good method for detecting camera, and slightly modifies it as follows 01: function checkforcam (){
02: camarray = camera. names;
03: If (camarray. length> = 1 ){
04: temp_cam = camera. Get ();
05: If (temp_cam =-1)
06: trace ('video Device Busy ');
07: else
08: trace ('video device ');
09: delete temp_cam;
10:} else if (camarray. Length = 0 ){
11: trace ('no video device ');
12 :}
13 :}
14 ://-----------------------------------------------------------------
15: // or the following functions are simpler:
16: function checkforcam (){
17: Return camera. Names. length;
18 :}
19: function iscambusy (){
20: If (arguments. Length) return camera. Get (arguments [0]) =-1;
21: Return camera. Get () =-1;
22 :}
23:

To set the mode of the camera object, use the setmode () method as follows: 1: mycamera. setmode (width, height, FPS [, favorsize])
2: // width. The height is the width and height of the camera object. The default value is 160 × 120.
3: // The default video capture rate is 15.
4: // favorsize is an optional Boolean value. The default value is true, indicating that the current window size is matched with the maximum rate. If it is set to false, the smoothness of the image is prioritized.

Recommended configurations for different bandwidths
The default camera settings provide the same adequate transmission quality for all bandwidths. If you need to manually set them to meet different bandwidth requirements, set the camera parameters as follows:

  1. Mycamera. setquality (bandwidth, framequality)
    // Bandwidth refers to the maximum number of bytes transmitted per second. The default value is 16384. If it is set to 0, the image quality set for framequality is maintained. Use the maximum bandwidth whenever possible.
  2.  
  3. // Compression Quality of freamquality images: 1 ~ 100. If it is set to 0, the image quality is automatically adjusted within the bandwidth setting range.
  4.  

The following are recommended settings for different bandwidths:

     

  1. [Modem]
    Low image quality, high motion smoothness my_cam.setquality (, 0)
    Relatively high image quality, low motion smoothness my_cam.setquality)
    DSL]
    Low image quality, high motion smoothness my_cam.setquality (12000,0)
    Relatively high image quality, low motion smoothness my_cam.setquality)
    Lan]
    Low image quality, high motion smoothness my_cam.setquality (, 0)
    Relatively high image quality, low motion smoothness my_cam.setquality (0,100)
  2.  
  3.  
  4. [
  5.  
  6.  
  7. [
  8.  
  9.  

After opening and setting camera, you must append it to a video object to display it.

  1. MyVideo.attachVideo(MyCamera);

Close camera normally
If your application uses the camera object and netstream object to record data, Camera remains open. To ensure that the camera object is disabled, use

  1. NetStream.attachVideo(false)

Use the same camera in multiple applications
Multiple applications (SWFs) can use one camera at the same time. Generally, multiple browser windows use the same process, so multiple applications in the browser environment can use the same camera normally. However, if one is running in a browser and the other is an independent application, the same camera cannot be shared, because camera cannot be shared by multiple processes.

Event Response
There are two important event responses in camera
1. The onstatus event muted attribute changes will trigger this event
An example in the original reference manual can describe onstatus usage 01: mycam = camera. Get ();
02: myvideoobject. attachvideo (mycam );
03: mycam. onstatus = function (infomsg ){
04: If (infomsg. Code = 'camera. muted ')
05 :{
06: trace ('user denies access to the camera ');
07 :}
08: else
09: trace ('user allows access to the camera ');
10 :}
11: // change the allow or deny value to invoke the Function
12: system. showsettings (0 );

2. Whether the onactivity Event video is Event Response
Please refer to the example in the original manual: 1: // assumes a video object named 'myvideoobject 'is on the stage
2: c = camera. Get ();
3: myvideoobject. attachvideo (C );
4: C. setmotionlevel (10,500 );
5: C. onactivity = function (Mode)
6 :{
7: trace (mode );
8 :};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.