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

    Viewing Camera in Flex 4

    pdvel Level 1

      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,

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

          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:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300" width="500" height="400" >
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
                         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= "";
                                   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);
               <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" 



          • 2. Re: Viewing Camera in Flex 4

            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);




            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.



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



              Thanks so much.