3 Replies Latest reply on Sep 29, 2011 11:14 AM by kielsoft

    Viewing Camera in Flex 4

    pdvel

      I'm wondering what the correct way is to display video from my webcam in Flex 4. Before, I'd just use the mx:VideoDisplay and attach the camera to that.But now, I can't really use that control since everything else is in spark now, and the spark version of VideoDisplay doesn't have anything similar to attachCamera. I've seen several posts by people with similar problems, but no concrete answers as to what the new way to do this is..
      Anyone who can shed some light on this?

       

      Thanks in advance,
      Peter

        • 1. Re: Viewing Camera in Flex 4
          kielsoft

          I have tried to get this work but I dont know what is wrong with the below code or my browser. maybe you can try it and let know if it works well or any modification you apply to make it work, so others can benefit from it.

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                            xmlns:s="library://ns.adobe.com/flex/spark" 
                            xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300" width="500" height="400" >
               <fx:Declarations>
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
               </fx:Declarations>
               <fx:Script>
                    <![CDATA[
                         import mx.controls.Alert;
                         import mx.events.FlexEvent;
                         
                         import org.osmf.net.StreamType;
                         
                         import spark.components.mediaClasses.DynamicStreamingVideoItem;
                         import spark.components.mediaClasses.DynamicStreamingVideoSource;
                         
                         private var _cam:DynamicStreamingVideoSource =  new DynamicStreamingVideoSource();
                         private var _dynVideoSource:DynamicStreamingVideoSource;
                         
                         protected function video_creationCompleteHandler(event:FlexEvent):void
                         {
                              _dynVideoSource=new DynamicStreamingVideoSource();
                              
                              var videoItems:Vector.<DynamicStreamingVideoItem>;
                              videoItems=new Vector.<DynamicStreamingVideoItem>();
                              videoItems[0]=new DynamicStreamingVideoItem();
                              
                              _dynVideoSource.host= "";
                              _dynVideoSource.streamType=StreamType.LIVE;
                              _dynVideoSource.streamItems=videoItems;
                              
                              myVideo.source=_dynVideoSource;
                              
                              if(myVideo.videoObject){
                                   Alert.show("Got Video Object: " + myVideo.videoObject, "Notification");
                              }
                              else {
                                   Alert.show("Unable To Get Video Object" + myVideo.videoObject, "Notification");
                              }
                              
                              var cam:Camera = Camera.getCamera(); //Camera.names[0]);
                              cam.setMode(640, 480, 15);
                              cam.setQuality(0, 80);
                              myVideo.videoObject.attachCamera(cam); 
                         }
                    ]]>
               </fx:Script>
               <s:Panel x="53" y="26" width="394" height="290" title="My Camera">
                    <s:VideoDisplay id="myVideo"
                                        x="10" y="10" 
                                        width="371" height="238" 
                                        creationComplete="video_creationCompleteHandler(event);"/>
               </s:Panel>
          </s:Application>
          
          

           

          Thamks

          • 2. Re: Viewing Camera in Flex 4
            andres-l-c

            I can see that a lot of people have got the same problem.

            The way to attach a webcam to a s:VideoDisplay component is this:

             

            var cam:Camera = Camera.getCamera(); //Camera.names[0]);

            cam.setMode(640, 480, 15);

            cam.setQuality(0, 80);

            var localCam:Video = new Video(640,480);

            localCam.attachCamera(cam);

            myVideo.addChild(localCam);

             

            As you see, you must attach the webcam to a Video object and then add it (using .addChild) to the s:VideoDisplay component.

            I hope it has helped you.

             

            Regards.

            • 3. Re: Viewing Camera in Flex 4
              kielsoft Level 1

              Andres,

               

              Thanks so much.