Unlike the previous MX version, the spark VideoDisplay component has no attachCamera function. The only other examples of Camera usage I have found have all revolved around attaching to a Video object. The problem is that this means you have to handle all the sizing etc... manually.
You can create a simple custom MediaElement class and add it to a MediaContainer in a custom UIComponent which will handle all of the sizing issues. This can be included via mxml in the same way VideoDisplay is.
package
{
import flash.events.Event;
import flash.media.Camera;
import mx.core.UIComponent;
import org.osmf.containers.MediaContainer;
public class CameraDisplay extends UIComponent
{
private var mediaContainer:MediaContainer;
private var element:CameraElement;
public function set camera(camera:Camera):void{
mediaContainer = new MediaContainer();
element = new CameraElement();
mediaContainer.width=width;
mediaContainer.height=height;
addChild(mediaContainer);
mediaContainer.addMediaElement(element);
element.camera = camera; //You have to wait until after adding the media element to the mediaContainer before setting the camera property as that will trigger the mediaContainers layout routines.
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(mediaContainer){
mediaContainer.width=unscaledWidth;
mediaContainer.height=unscaledHeight;
}
}
}
}
This can be combined with the following MediaElement extension Class:
package
{
import flash.media.Camera;
import flash.media.Video;
import org.osmf.media.MediaElement;
import org.osmf.traits.DisplayObjectTrait;
import org.osmf.traits.MediaTraitType;
public class CameraElement extends MediaElement
{
public function set camera(camera:Camera):void{
var video:Video = new Video(camera.width * 2, camera.height * 2);
video.attachCamera(camera);
var displayObjectTrait:DisplayObjectTrait = new DisplayObjectTrait(video, camera.width, camera.height);
addTrait(MediaTraitType.DISPLAY_OBJECT,displayObjectTrait);
}
}
}
+