How do I attach camera to Spark.components.VideoDisplay

£可爱£侵袭症+ 提交于 2019-12-03 16:32:14
Tony

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

Straight up, the answer is that you can't attach a camera to the Spark VideoDisplay. Sorry. I was trying to make this happen too, but I had to default to the mx VideoDisplay and there's nothing wrong with using it :)

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

Gratuz

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

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

_cam = new DynamicStreamingVideoSource();

<s:VideoDisplay id="mycam" source="_cam" />

then, in the creationComplete handler of the application i did this

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

this resolved the issue.

Been looking for a solution to this and found the 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

Shorter workaround:

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

In this case, the Video object can be then referenced as camVideoDisplay.videoObject, e.g.:

camVideoDisplay.videoObject.attachCamera( .. );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!