How to connect the camera to Spark.components.VideoDisplay

I use Flash Builder and created a Flex Flex Flex project that will broadcast video from a local camera. If I use mx.controls.VideoDisplay ; no problem, since it has an attachCamera(camera) method. But the Spark VideoDisplay component VideoDisplay not have this method. I know that I can use mx controls in a Spark application, but I want to know:

  • What is the real difference between spark.components.VideoDisplay and mx.controls.VideoDisplay ?
  • How to connect the camera to spark.components.VideoDisplay ?
  • Are there any advantages if I go with spark (since it is newer for mx library)?

thanks.

EDIT . The documentation mentions: "Starting with Flex 4.0, Adobe recommends using the spark.components.VideoPlayer class as an alternative to this class. (Mx.controls.VideoDisplay)"

+4
source share
5 answers

Here is what you need for this:

 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 application1_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; mycam.source=_dynVideoSource; var cam:Camera = Camera.getCamera(); //Camera.names[0]); cam.setMode(640, 480, 15); cam.setQuality(0, 80); mycam.videoObject.attachCamera(cam); } 
+14
source

Right, the answer is that you cannot attach the camera to Spark VideoDisplay . I'm sorry. I tried to do this too, but I had to use mx VideoDisplay by default, and nothing happened to it :)

Spark is newer, and I prefer to use it whenever possible, but in this case you just need to use the MX control. It happens.

+4
source

I tried connecting the camera to videoDisplay.videoObject - but the videoObject was always null, which throws an error.

To decide that I created a dummy DynamicStreamingVideoObject and passed it as a source

 _cam = new DynamicStreamingVideoSource(); <s:VideoDisplay id="mycam" source="_cam" /> 

then in the creationComplete application handler i did this

 var cam:Camera = Camera.getCamera(); mycam.videoObject.attachCamera(cam); 

this solved the problem.

+2
source

Looking for a solution to this and found below

 var cam:Camera = Camera.getCamera(); cam.setMode(320, 240, 15); cam.setQuality(0, 0); var myCam:Video = new Video(320,240); myCam.attachCamera(cam); myVideo.addChild(myCam); 

thanks

+2
source

Shorter workaround:

 <s:VideoDisplay id="camVideoDisplay" source="dummy" autoPlay="false" autoDisplayFirstFrame="false"/> 

In this case, the Video object can then be specified as camVideoDisplay.videoObject , for example:

 camVideoDisplay.videoObject.attachCamera( .. ); 
0
source

All Articles