actionscript-3apache-flexflash-buildermxmlflex-spark

How do I attach camera to Spark.components.VideoDisplay


I'm using Flash Builder and created a spark-application Flex project that will stream video from the local camera. If I use mx.controls.VideoDisplay; there is no problem since it has attachCamera(camera) method. But Spark's VideoDisplay component does not have that method. I know I can use mx controls inside a Spark app but I want to know:

thanks.

EDIT: In the documentation this is mentioned: "Starting with Flex 4.0, Adobe recommends that you use the spark.components.VideoPlayer class as an alternative to this class. (mx.controls.VideoDisplay)"


Solution

  • Here are the specifics to get this working:

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